The "getRecordsByIds" action retrieves one or more records from a database table using their IDs. The response message contains one record for each ID specified in the "id" array.
- A table must have a primary key or ID to retrieve records.
- Tables created by the
"createTable"action, automatically have an auto increment"id"field indexed as a 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
"getRecordsByIds"action provides an optional"primaryKeys"property that can retrieve records using any primary key index. - The
"primaryKeys"property:- can be used to retrieve one or more records from a database table using primary key identifiers
- is required if
"id"is omitted - is
"null"if using"ids"
- The
"id"property:- is required if
"primaryKeys"is omitted and supplied by the client to uniquely identify each request - is
"null"if using the"primaryKeys"property - is the client's message identifier and should be a string containing a value that is unique to the client
- may also be a number, array, or object (this is discouraged)
- is required if
- In asynchronous protocols, such as MQTT,
"getRecordsByIds"enables the client to associate response messages with the original request messages since the server adds this property (with the client's value) to each response message. - JSON DB API sends a response message with an error if
"id"is missing ornull. Although jsonAction allows the"id"to benullor omitted, JSON DB API does not. - The server includes the
"id"in reply messages using the exact value and data type that the client supplied in the request. If the client sends a string, the server replies with the identical string. If it sends a number, the server replies with the identical number. This behavior is required by jsonAction. A string is preferred because it is the fastest and easiest for the server to return the identical value. If a number is used, it should be an integer to avoid differences in binary rounding behavior between the client and the server. - The
"id"should be unique from the client's perspective. From the server's perspective, the true unique"id"of a request-response message pair is the combination of the client id plus the server’s auth id for that client. The"id"will likely not be unique from the server's perspective since different clients can use the same"id"values).
- Retrieving one record by its ID
- Loading a previously saved set of IDs to quickly retrieve a set of records
- Using foreign key IDs to look up records
- The fastest way to retrieve a specific record is to look it up by its ID.
- Results start to return more slowly as more records are requested.
Request examples
Arrays
{
"api": "db",
"action": "getRecordsByIds",
"requestId": "1",
"params": {
"tableName": "athlete",
"ids": [
3
]
},
"responseOptions": {
"dataFormat": "arrays"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}"primaryKeys"
{
"api": "db",
"action": "getRecordsByIds",
"requestId": "2",
"params": {
"databaseName": "ctreeSQL",
"tableName": "athlete",
"primaryKeys": [
[
{
"fieldName": "id",
"value": 3
}
]
]
},
"responseOptions": {
"dataFormat": "objects"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Return objects
{
"api": "db",
"apiVersion": "1.0",
"requestId": "3",
"action": "getRecordsByIds",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "athlete",
"ids": [
6,
2,
4
]
},
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string",
"includeFields": [],
"excludeFields": []
},
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Maximal
{
"api": "db",
"action": "getRecordsByIds",
"requestId": "1",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "athlete",
"fixedLengthCharFormat": "sql",
"bookmarks": [
"00000001",
"00000002"
]
"ids": [
3
]
},
"responseOptions": {
"includeBookmarks": false,
"dataFormat": "objects",
"binaryFormat": "hex",
"numberFormat": "string",
"variantFormat": "variantObject",
"includeFields": [
"name",
"ranking"
],
"excludeFields": []
},
"debug": "max",
"requestId": "3",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response examples
Arrays
{
"result": {
"dataFormat": "arrays",
"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": 30,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "ranking",
"type": "smallint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": false,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "birthDate",
"type": "date",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "playerNumber",
"type": "number",
"length": 32,
"scale": 6,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "livedPast2000",
"type": "bit",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "earnings",
"type": "money",
"length": 32,
"scale": 4,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "favoriteSaying",
"type": "varchar",
"length": 500,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
}
],
"data": [
[
3,
1291366,
"Muhammad Ali",
3,
"1942-01-17",
1,
true,
60000000,
"Float like a butterfly, sting like a bee."
]
],
"primaryKeyFields": [
"id"
],
"changeIdField": "changeId",
"moreRecords": false,
"requestedRecordCount": 0,
"returnedRecordCount": 1,
"totalRecordCount": 1
},
"requestId": "3",
"debugInfo": {
"request": {
"api": "db",
"action": "getRecordsByIds",
"params": {
"databaseName": "ctreeSQL",
"tableName": "athlete",
"primaryKeys": [
[
{
"fieldName": "id",
"value": 3
}
]
]
},
"requestId": "2",
"responseOptions": {
"dataFormat": "arrays"
},
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
},
"serverSuppliedValues": {
"databaseName": "ctreeSQL",
"ownerName": "admin"
},
"errorData": {
"errorData": null
},
"warnings": []
},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}Objects
{
"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": 30,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "ranking",
"type": "smallint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": false,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "birthDate",
"type": "date",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "playerNumber",
"type": "number",
"length": 32,
"scale": 6,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "livedPast2000",
"type": "bit",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "earnings",
"type": "money",
"length": 32,
"scale": 4,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "favoriteSaying",
"type": "varchar",
"length": 500,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
}
],
"data": [
{
"birthDate": "1969-01-03",
"changeId": "1291366",
"earnings": "990000000",
"favoriteSaying": "Once something is a passion, the motivation is there.",
"id": "6",
"livedPast2000": true,
"name": "Michael Schumacher",
"playerNumber": "1",
"ranking": "6"
},
{
"birthDate": "1895-02-06",
"changeId": "1291366",
"earnings": "800000",
"favoriteSaying": "Every strike brings me closer to the next home run.",
"id": "2",
"livedPast2000": false,
"name": "Babe Ruth",
"playerNumber": "3",
"ranking": "2"
},
{
"birthDate": "1940-10-23",
"changeId": "1291366",
"earnings": "115000000",
"favoriteSaying": "Everything is practice.",
"id": "4",
"livedPast2000": true,
"name": "Pele",
"playerNumber": "10",
"ranking": "4"
}
],
"primaryKeyFields": [
"id"
],
"changeIdField": "changeId",
"moreRecords": false,
"requestedRecordCount": 3,
"returnedRecordCount": 3,
"totalRecordCount": 3
},
"requestId": "3",
"debugInfo": {
"request": {
"api": "db",
"action": "getRecordsByIds",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "athlete",
"ids": [
6,
2,
4
]
},
"apiVersion": "1.0",
"requestId": "3",
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string",
"includeFields": [],
"excludeFields": []
},
"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. 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 |
fixedLengthCharFormat |
The
For more details, see |
Optional with default "sql"
|
string |
|
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 specifications 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. |
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 .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 default value of a field. |
string | 0 to 65,500 bytes |
|
fields .length |
Identifies the length of the field. | integer |
1 to 65500 |
|
fields .name |
The The The
|
string | 1 to 64 bytes |
|
fields .nullable |
"nullable" identifies whether a field can contain a NULL value. |
Boolean |
|
|
fields .primaryKey |
When > 0, the "primaryKey" property identifies the ordinal position of the field within the table's primary key. |
integer |
0 to 32
|
|
fields .scale |
If the type is "number" or "money", the "scale" property identifies the number of places to the right of the decimal point,. |
integer |
0 to 32
|
|
fields .type |
Identifies the type of the field. See Data types. | string |
|
moreRecords |
The "moreRecords" property indicates if there are more records that match the filters in the request. |
Boolean |
|
primaryKeyFields |
This property specifies the fields of the table’s primary key when multiple fields are combined to form the primary key.
The order of fields in this property is the order of fields in the primary key index. The A primary key with multiple fields has an index named If only one field is used as the primary key, the
Example "primaryKeyFields": [
"a",
"b",
"c"
],
"fields": [
{
"name": "a",
"type": "tinyint"
},
{
"name": "b",
"type": "smallint"
},
{
"name": "c",
"type": "integer"
}
] |
array | an array |
requestedRecordCount |
The
|
integer |
|
returnedRecordCount |
The
|
integer |
|
totalRecordCount |
The
|
integer |
|