"insertRecords"
(jsonAction)
JSON DB "insertRecords"
action inserts records into a table
The "insertRecords"
action inserts one or more records into a table.
Request examples
Insert into test1
table using objects
{
"requestId": "1",
"api": "db",
"action": "insertRecords",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "test1",
"dataFormat": "objects",
"sourceData": [
{
"name": "test name 1"
},
{
"name": "test name 2"
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
{
"requestId": "2",
"api": "db",
"action": "insertRecords",
"params": {
"tableName": "test1",
"dataFormat": "arrays",
"fieldNames": [
"name"
],
"sourceData": [
[
"test name 3"
],
[
"test name 4"
]
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
{
"api": "db",
"apiVersion": "1.0",
"requestId": "3",
"action": "insertRecords",
"params": {
"databaseName": "ctreeSQL",
"tableName": "athlete",
"dataFormat": "objects",
"sourceData": [
{
"name": "Michael Jordan",
"ranking": 1,
"birthDate": "19630217",
"playerNumber": 23,
"livedPast2000": true,
"earnings": 1700000000,
"favoriteSaying": "There is no 'i' in team but there is in win."
},
{
"name": "Babe Ruth",
"ranking": 2,
"birthDate": "18950206",
"playerNumber": 3,
"livedPast2000": false,
"earnings": 800000,
"favoriteSaying": "Every strike brings me closer to the next home run."
},
{
"name": "Muhammad Ali",
"ranking": 3,
"birthDate": "19420117",
"playerNumber": 1,
"livedPast2000": true,
"earnings": 60000000,
"favoriteSaying": "Float like a butterfly, sting like a bee."
},
{
"name": "Pele",
"ranking": 4,
"birthDate": "19401023",
"playerNumber": 10,
"livedPast2000": true,
"earnings": 115000000,
"favoriteSaying": "Everything is practice."
},
{
"name": "Wayne Gretzky",
"ranking": 5,
"birthDate": "19610126",
"playerNumber": 99,
"livedPast2000": true,
"earnings": 1720000,
"favoriteSaying": "You miss 100 percent of the shots you never take."
},
{
"name": "Michael Schumacher",
"ranking": 6,
"birthDate": "19690103",
"playerNumber": 1,
"livedPast2000": true,
"earnings": 990000000,
"favoriteSaying": "Once something is a passion, the motivation is there."
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
{
"requestId": "4",
"api": "db",
"action": "insertRecords",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "all_types",
"dataFormat": "objects",
"binaryFormat": "hex",
"sourceData": [
{
"nested_json_object_or_array": {
"hello": "world"
},
"boolean_byte": true,
"signed_int8": -128,
"signed_int16": -32768,
"signed_int32": -2147483648,
"signed_int64": -9223372036854776000,
"ieee_base2float32": -0.000001,
"ieee_base2float64": "-9223372036800000000.0",
"signed32digits_base10_left32right0": "-12345678901234567890123456789012",
"signed32digits_base10_left0right32": "-0.12345678901234567890123456789012",
"signed32digits_base10_left20right12": "-12345678901234567890.123456789012",
"signed32digits_base10_left30right2": "-123456789012345678901234567890.12",
"signed32digits_base10_left28right4": "-1234567890123456789012345678.9012",
"date_yyyymmdd": "2023-04-18",
"time_hhmmssfff": "15:43:59.013",
"datetime_yyyymmddthhmmssfff": "2023-04-18T15:43:59.013",
"fixed_string_10bytes": "_ 3456 _",
"variable_string_up_to_max65500bytes": "Variable-length string up to 65,500 bytes.",
"variable_string_up_to_2GB": "Variable-length string up to 2GB in length.",
"fixed_binary_10bytes": "FF00FF",
"variable_binary_up_to_max65500bytes": "FF00FF",
"variable_binary_up_to_2GB": "FF00FF"
}
]
},
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string"
},
"apiVersion": "1.0",
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
{
"result": {
"dataFormat": "objects",
"binaryFormat": "hexadecimal",
"fields": [
{
"name": "id",
"type": "bigint",
"length": null,
"scale": null,
"autoTimestamp": "none",
"defaultValue": null,
"nullable": false,
"primaryKey": 1
},
{
"name": "changeId",
"type": "bigint",
"length": null,
"scale": null,
"autoTimestamp": "none",
"defaultValue": null,
"nullable": true,
"primaryKey": 0
},
{
"name": "name",
"type": "varchar",
"length": 50,
"scale": null,
"autoTimestamp": "none",
"defaultValue": null,
"nullable": true,
"primaryKey": 0
}
],
"data": []
},
"requestId": "1",
"errorCode": 4014,
"errorMessage": "field 'BOGUS' does not belong to the table",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
{
"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": [
{
"changeId": 1289789,
"id": 1,
"name": "test name 1"
},
{
"changeId": 1289789,
"id": 2,
"name": "test name 2"
}
],
"primaryKeyFields": [
"id"
],
"changeIdField": "changeId"
},
"requestId": "1",
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
{
"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": "nested_json_object_or_array",
"type": "json",
"length": 65500,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "boolean_byte",
"type": "bit",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed_int8",
"type": "tinyint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed_int16",
"type": "smallint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed_int32",
"type": "integer",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed_int64",
"type": "bigint",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "ieee_base2float32",
"type": "real",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "ieee_base2float64",
"type": "float",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed32digits_base10_left32right0",
"type": "number",
"length": 32,
"scale": 0,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed32digits_base10_left0right32",
"type": "number",
"length": 32,
"scale": 32,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed32digits_base10_left20right12",
"type": "number",
"length": 32,
"scale": 12,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed32digits_base10_left30right2",
"type": "money",
"length": 32,
"scale": 2,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "signed32digits_base10_left28right4",
"type": "money",
"length": 32,
"scale": 4,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "date_yyyymmdd",
"type": "date",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "time_hhmmssfff",
"type": "time",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "datetime_yyyymmddthhmmssfff",
"type": "timestamp",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "fixed_string_10bytes",
"type": "char",
"length": 10,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "variable_string_up_to_max65500bytes",
"type": "varchar",
"length": 65500,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "variable_string_up_to_2GB",
"type": "lvarchar",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "fixed_binary_10bytes",
"type": "binary",
"length": 10,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "variable_binary_up_to_max65500bytes",
"type": "varbinary",
"length": 65500,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
},
{
"name": "variable_binary_up_to_2GB",
"type": "lvarbinary",
"length": null,
"scale": null,
"defaultValue": null,
"nullable": true,
"primaryKey": 0,
"autoValue": "none"
}
],
"data": [
{
"boolean_byte": true,
"changeId": "1293834",
"date_yyyymmdd": "2023-04-18",
"datetime_yyyymmddthhmmssfff": "2023-04-18T15:43:59.013",
"fixed_binary_10bytes": "FF00FF00000000000000",
"fixed_string_10bytes": "_ 3456 _",
"id": "1",
"ieee_base2float32": "-1e-06",
"ieee_base2float64": "-9.22337e+18",
"nested_json_object_or_array": {
"hello": "world"
},
"signed32digits_base10_left0right32": "-0.12345678901234567890123456789012",
"signed32digits_base10_left20right12": "-12345678901234567890.123456789012",
"signed32digits_base10_left28right4": "-1234567890123456789012345678.9012",
"signed32digits_base10_left30right2": "-123456789012345678901234567890.12",
"signed32digits_base10_left32right0": "-12345678901234567890123456789012",
"signed_int16": "-32768",
"signed_int32": "-2147483648",
"signed_int64": "-9223372036854775808",
"signed_int8": "-128",
"time_hhmmssfff": "15:43:59.013",
"variable_binary_up_to_2GB": "FF00FF",
"variable_binary_up_to_max65500bytes": "FF00FF",
"variable_string_up_to_2GB": "Variable-length string up to 2GB in length.",
"variable_string_up_to_max65500bytes": "Variable-length string up to 65,500 bytes."
}
],
"primaryKeyFields": [
"id"
],
"changeIdField": "changeId"
},
"requestId": "4",
"debugInfo": {
"request": {
"api": "db",
"action": "insertRecords",
"params": {
"databaseName": "ctreeSQL",
"ownerName": "admin",
"tableName": "all_types",
"dataFormat": "objects",
"binaryFormat": "hex",
"sourceData": [
{
"nested_json_object_or_array": {
"hello": "world"
},
"boolean_byte": true,
"signed_int8": -128,
"signed_int16": -32768,
"signed_int32": -2147483648,
"signed_int64": -9223372036854776000,
"ieee_base2float32": -0.000001,
"ieee_base2float64": "-9223372036800000000.0",
"signed32digits_base10_left32right0": "-12345678901234567890123456789012",
"signed32digits_base10_left0right32": "-0.12345678901234567890123456789012",
"signed32digits_base10_left20right12": "-12345678901234567890.123456789012",
"signed32digits_base10_left30right2": "-123456789012345678901234567890.12",
"signed32digits_base10_left28right4": "-1234567890123456789012345678.9012",
"date_yyyymmdd": "2023-04-18",
"time_hhmmssfff": "15:43:59.013",
"datetime_yyyymmddthhmmssfff": "2023-04-18T15:43:59.013",
"fixed_string_10bytes": "_ 3456 _",
"variable_string_up_to_max65500bytes": "Variable-length string up to 65,500 bytes.",
"variable_string_up_to_2GB": "Variable-length string up to 2GB in length.",
"fixed_binary_10bytes": "FF00FF",
"variable_binary_up_to_max65500bytes": "FF00FF",
"variable_binary_up_to_2GB": "FF00FF"
}
]
},
"apiVersion": "1.0",
"requestId": "4",
"responseOptions": {
"binaryFormat": "hex",
"dataFormat": "objects",
"numberFormat": "string"
},
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
},
"serverSuppliedValues": {
"databaseName": "ctreeSQL",
"ownerName": "admin"
},
"errorData": {
"errorData": null
},
"warnings": []
},
"errorCode": 0,
"errorMessage": "",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Use the insertRecords JSON API action to insert records into a table
The "params"
property is an object that contains an action's parameters. Each action defines its own required and optional properties.
"params"
property summariesProperty | Description | Default | Type | Limits (inclusive) | |||
---|---|---|---|---|---|---|---|
(optional) specifies how binary values are returned |
| string | One of the following: | ||||
(optional) specifies the name of a database | Defaults to the | string | 1 to 64 bytes | ||||
(optional) specifies the returned results as an array of array, an array of objects, or the default setting defined at login |
| string |
| ||||
(optional) specifies the names of fields in a table |
When | array | 1 to 64 bytes | ||||
(optional) specifies the unique name of a schema in a database |
| string | 1 to 64 bytes | ||||
sourceData | (optional) contains either an array of objects or an array of arrays (depending on the specified |
| array | ||||
specifies the name of a table | Required - No default value | string | 1 to 64 bytes |
The "databaseName"
property is an optional string that specifies the database that contains the tables. It defaults to the database name supplied at login.
Note
In the API Explorer, "defaultDatabaseName"
is set to "ctreeSQL"
in the "createSession"
action that happens at login.
A zero-length
"databaseName"
is invalid.Its limits are from 0 to 64 bytes.
If the
"databaseName"
property is omitted or set tonull
, the server will use the default database name specified at login.If no default database is specified during
"createSession"
,"defaultDatabaseName"
will be set to the"defaultDatabaseName"
value that is specified in theservices.json
file.
The "dataFormat"
property is an optional, case-insensitive string enum that defines the format of the response in the "data"
property. The default format is an array of arrays. The alternative is an array of objects. The default for "dataFormat"
can be changed during a "createSession"
action by assigning a different value to the "dataFormat"
property in "defaultResponseOptions"
.
"dataFormat"
property:Two of those versions occur in a request and another occurs in a response. They all indicate how data is formatted.
"dataFormat"
in the request inside"responseOptions"
determines how the"data"
property in the response is formatted.Possible values include:
"arrays"
This is the default and causes the server to return results as an array of arrays, which is the most efficient.
"objects"
This returns results as an array of objects. This is less efficient but is simpler to generate, read, and troubleshoot.
"dataFormat"
in the request in the"params"
object notifies the server how the"sourceData"
property is formatted in the request. This version is rarely used because of the default"autoDetect"
behavior.Possible values include:
"arrays"
This causes the server to return results as an array of arrays, which is the most efficient.
"objects"
This returns results as an array of objects. This is less efficient but is simpler to generate, read, and troubleshoot.
"autoDetect"
This is the default and causes the server to automatically detect the format of the data in the
"sourceData"
property.
"dataFormat"
in the response shows the client how the server formatted the"data"
property.Possible values include:
"arrays"
This is the default and causes the server to return results as an array of arrays, which is the most efficient.
"objects"
This returns results as an array of objects. This is less efficient but is simpler to generate, read, and troubleshoot.
The "fieldNames"
property is an optional, case-sensitive array of strings where each string is the name of a field. It defaults to an empty array.
"fieldNames"
is required in two possible cases:When
"dataFormat"
is set to"arrays"
.When
"dataFormat"
is set to"autoDetect"
and the value in"sourceData"
is an array of arrays.
It is recommended to create tables with all lowercase
"fieldNames"
.
The "ownerName"
property is an optional string from 1 to 64 bytes that specifies the account that owns an object.
The "tableName"
property is a string containing the name of a table.
A table name may contain up to 64 ASCII characters and must not start with a number.
"result"
property summariesProperty | Description | Type | Limits (inclusive) | |||
---|---|---|---|---|---|---|
specifies how binary values are returned | string | One of the following: | ||||
data | (optional) specifies an array or object that the server returns, such as records returned by a query. It is always included in a response but contains an empty array when no results are available. | array | Its contents are determined by the action | |||
specifies the format of the data in the | string |
| ||||
specifies an array of objects set by the server, where each object is the definition of a field in a table defining the details of each field returned by a query | array |
The "dataFormat"
property is an optional, case-insensitive string enum that defines the format of the response in the "data"
property. The default format is an array of arrays. The alternative is an array of objects. The default for "dataFormat"
can be changed during a "createSession"
action by assigning a different value to the "dataFormat"
property in "defaultResponseOptions"
.
"dataFormat"
property:Two of those versions occur in a request and another occurs in a response. They all indicate how data is formatted.
"dataFormat"
in the request inside"responseOptions"
determines how the"data"
property in the response is formatted.Possible values include:
"arrays"
This is the default and causes the server to return results as an array of arrays, which is the most efficient.
"objects"
This returns results as an array of objects. This is less efficient but is simpler to generate, read, and troubleshoot.
"dataFormat"
in the request in the"params"
object notifies the server how the"sourceData"
property is formatted in the request. This version is rarely used because of the default"autoDetect"
behavior.Possible values include:
"arrays"
This causes the server to return results as an array of arrays, which is the most efficient.
"objects"
This returns results as an array of objects. This is less efficient but is simpler to generate, read, and troubleshoot.
"autoDetect"
This is the default and causes the server to automatically detect the format of the data in the
"sourceData"
property.
"dataFormat"
in the response shows the client how the server formatted the"data"
property.Possible values include:
"arrays"
This is the default and causes the server to return results as an array of arrays, which is the most efficient.
"objects"
This returns results as an array of objects. This is less efficient but is simpler to generate, read, and troubleshoot.
The "fields"
property is a required array of field-type objects. There is one object for each top-level field in the array. Each object identifies the actual data type of the field as stored in the database.
A field-type object is used when creating a table. It contains one object for each field definition returned in the data.
Full request example
"fields":
[
{
"name": "name",
"type": "varchar",
"length": 50,
"scale": null,
"defaultValue": null,
"nullable": false,
"primaryKey":1
}
]
Full response example
"fields":
[
{
"name": "id",
"type": "bigint",
"length": null,
"scale": null,
"autoValue": "none",
"defaultValue": null,
"nullable": false,
"primaryKey": 1
}
]