The "deleteRecords" action deletes records from a database table using its primary key, such as the id field.
- The action returns the values from the deleted records in case you want to insert them again, view them, or verify the correct records are deleted.
- If the specified records do not exist, the action returns success because this is the desired end result.
- The
"totalRecordCount"property in the response is the number of records that are deleted by this action. - A table must have a primary key to delete records.
- Tables created by the
"createTable"action, automatically have an auto increment"id"field indexed as primary key. - Tables created by other APIs may not have an
"id"field; instead, they may have a primary key index that includes one or more fields in the table. - The
"deleteRecords"action provides an optional"primaryKeys"property that can retrieve records using any primary key index. - The
"primaryKeys"and"ids"properties are mutually exclusive.
- Tables created by the
- Use the
"primaryKeys"property to delete records from a table that uses a natural primary key instead of the identity field.- The outer array allows you to delete multiple records.
- The inner array defines the field values of each primary key field. It must be an array because primary keys may contain multiple fields.
Request examples
Minimal
{
"action": "deleteRecords",
"params": {
"tableName": "test1",
"ids": [
1,
2
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Delete one record using a multi-field primary key
{
"api": "db",
"action": "deleteRecords",
"params":
{
"tableName": "pk_example",
"primaryKeys":
[
[
{
"fieldName": "first_name",
"value": "Sam"
},
{
"fieldName": "last_name",
"value": "I-am"
}
]
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Delete multiple records using a multi-field primary key
This example deletes two records. The outer array identifies each record. The inner array specifies the field values of each record’s primary key: "first_name" and "last_name".
{
"api": "db",
"action": "deleteRecords",
"params":
{
"tableName": "pk_example",
"primaryKeys":
[
[
{
"fieldName": "first_name",
"value": "Sam"
},
{
"fieldName": "last_name",
"value": "I-am"
}
],
[
{
"fieldName": "first_name",
"value": "The Cat"
},
{
"fieldName": "last_name",
"value": "in the Hat"
}
]
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Maximal
{
"api": "db",
"apiVersion": "1.0",
"requestId": "4",
"action": "deleteRecords",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "test1",
"bookmarks": [
"00000001",
"00000002"
]
"ids": [
1,
2
]
},
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string",
"includeFields": [],
"excludeFields": [],
},
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response examples
Note If the target object does not exist, the response returns success, and the debug property contains a warning that the object was not found.
Minimal
{
"result": {
"dataFormat": "objects",
"binaryFormat": "hex",
"fields": [
{
"name": "id",
"type": "bigint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": false,
"primaryKey": 1,
"autoValue": "incrementOnInsert"
},
{
"name": "changeId",
"type": "bigint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "changeId"
},
{
"name": "name",
"type": "varchar",
"length": 50,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
}
],
"data": [],
"primaryKeyFields": [
"id"
],
"changeIdField": "changeId",
"totalRecordCount": 0
},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Maximal
{
"result": {
"dataFormat": "objects",
"binaryFormat": "hexadecimal",
"fields": [
{
"name": "id",
"type": "bigint",
"length": null,
"scale": null,
"autoTimestamp": "none",
"defaultValue": null,
"nullable": false
},
{
"name": "changeId",
"type": "bigint",
"length": null,
"scale": null,
"autoTimestamp": "none",
"defaultValue": null,
"nullable": true
},
{
"name": "name",
"type": "varchar",
"length": 50,
"scale": null,
"autoTimestamp": "none",
"defaultValue": null,
"nullable": true
}
],
"data": [
{
"changeId": 22788,
"id": 2,
"name": "jane"
}
],
"totalRecordCount": 1
},
"requestId": "4",
"debugInfo": {
"request": {
"api": "db",
"action": "deleteRecords",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "test1",
"ids": [
2
]
},
"apiVersion": "1.0",
"requestId": "4",
"responseOptions": {},
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
},
"serverSuppliedValues": {
"databaseName": "ctreeSQL",
"ownerName": "admin"
},
"errorData": {
"errorData": null
},
"warnings": []
},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Properties
Request properties ("params")
| Property | Description | Default | Type | Limits (inclusive) |
|---|---|---|---|---|
bookmarks |
The
Example
|
Optional with default of []
|
array of strings | 0 to 2048 bytes |
databaseName |
The You specify this property when you want to use a different database instead of the default. Your session's account must have the appropriate privileges to access the code package. This property is useful because objects, such as tables and code packages, can have the same name in multiple databases. This feature allows you to create multiple environments in the same server and reuse the same JSON actions in each environment. For example, you can create It is an error to set If no default database is specified during |
Defaults to the session's "defaultDatabaseName" property |
string | 1 to 64 bytes |
ids |
The
|
Optional with default of Required when |
array | 0 or more ids |
ownerName |
The You specify this property when you want to use a different account instead of the default. Your session's account must have the appropriate privileges to access the code package. This property is useful because objects, such as tables and code packages, can have the same name in the same database as long as different accounts own each object. This feature allows you to create duplicate objects for different users on the same server and reuse the same JSON actions on those objects. For example, an administrator can copy objects from a production environment to her account so she can troubleshoot an issue using the same JSON actions, JavaScript, and SQL code. It is an error to set If no default owner is specified during |
Optional with default of the session's "defaultOwnerName" property |
string | 1 to 64 bytes |
primaryKeys |
The |
Optional with default of Required when |
array of arrays |
1 or more array of key/value pairs. |
|
primaryKeys .fieldName |
The "fieldName" property specifies the name of a field in a table. |
Required - No default value | string | 1 to 64 bytes |
|
primaryKeys .value |
The
In Key-Value actions, the required |
Required - No default value | string |
|
tableName |
The See table name in System limits for the table naming requirements and limitations.
"params": {
"tableName": "ctreeTable"
} |
Required - No default value | string | 1 to 64 bytes |
Response properties ("result")
| Property | Description | Type | Limits (inclusive) |
|---|---|---|---|
binaryFormat |
The "binaryFormat" property designates the format of binary values embedded in JSON strings. See binaryFormat for more details. |
string | One of the following: "base64", "hex", or "byteArray". |
changeIdField |
This property's value designates the name of the field used for change-tracking functionality if you are not using the
However, if you use the name |
string | 1 to 64 bytes |
data |
The |
array of objects | The action determines its contents. |
|
data .changeId |
The "changeId" property specifies a unique, server-generated id. When this property is present, the database compares the value of "changeId" to the current transaction number stored in the "changeId" field of the record. This ensures an update does not modify a record that has subsequently been modified by another operation. |
integer | No limit |
|
data .id |
The |
integer |
|
|
data .name |
The The The
|
string | 1 to 64 bytes |
dataFormat |
The
|
string |
|
fields |
The
"fields": [
{
"autoValue": "none",
"name": "name",
"type": "varchar",
"length": 50,
"scale": null,
"defaultValue": null,
"nullable": false
}
] |
array |
updateRecords and deleteRecords only:
|
|
fields .autoTimestamp |
This The value is an official timestamp of the date and time when the server inserted or updated the associated field. The timezone is always UTC time (ZULU time). Once set, the value cannot be changed. When the value is When the value is When the value is "fields": [
{
"name": "name",
"type": "timestamp",
"autoTimestamp": "onupdate"
}
] |
string |
|
|
fields .autoValue |
The "autoValue" property indicates when and how the server automatically sets the field value. See autoValue for more details. |
string |
Some actions only:
|
|
fields .defaultValue |
The "defaultValue" property specifies the field's default value. |
string | 0 to 65,500 bytes |
|
fields .length |
The "length" property identifies the length of the field. |
integer |
1 to 65500 |
|
fields .name |
The The The |
string | 1 to 64 bytes |
|
fields .nullable |
The "nullable" property identifies whether a field can contain a NULL value. |
Boolean |
|
|
fields .primaryKey |
The |
integer |
0 to 32
|
|
fields .scale |
The The value of A scale of The You may optionally use the Example numbers allowed in "number" and "money" field types with a length of 4 and a scale from 0 to 4.
Request Example Create a table that contains all field types that use the "fields": [
{
"name": "j",
"type": "number",
"scale": 32
},
{
"name": "k",
"type": "number",
"scale": 4
} |
integer |
0 to 32
|
|
fields .type |
The
Request example "fields": [
{
"name": "j",
"type": "number"
}
] |
string |
|
primaryKeyFields |
The "primaryKeyFields" property specifies the fields to use for the table’s primary key. For more details, see "primaryKeyFields". |
array of strings | ["field1", …,"fieldN"] |
totalRecordCount |
The
|
integer |
|