Saving Multiple Objects¶
This API stores multiple objects in a data table with a single request. Consider the following example, it demonstrates an API call which saves two objects in the Person
data table:
curl -X POST \
-H 'Content-Type: application/json' \
-d '[ \
{ "name": "Joe", "age": 24 }, \
{ "name": "Betty", "age": 34 } \
]' \
https://xxxx.backendless.app/api/data/bulk/Person
The result of running the sample above is two objects saved in the database:
Method¶
POST
Endpoint URL¶
The xxxx.backendless.app
is a subdomain assigned to your application. For more information see the Client-side Setup section of this documentation.
https://xxxx.backendless.app/api/data/bulk/<table-name>
where:
Argument | Description |
---|---|
<table-name> |
Name of the table where the objects need to be saved. If the table does not exist and Dynamic Schema Definition is enabled (it is turned on by default), Backendless creates the table and configures its schema to match the objects structure. |
Request Headers¶
Content-Type:application/json
user-token: value-of-the-user-token-header-from-login
where:
Argument | Description |
---|---|
Content-Type |
Must be set to application/json . This header is mandatory. |
user-token |
Optional header. Contains a value returned by Backendless in a preceding user Login API call. If user-token is set in the request, the currently logged in user will be assigned to the ownerId property of the objects which are being saved. Additionally, the operation will be executed with the security policy associated currently logged in user. This means all permissions associated with the user and the roles assigned to the user will be enforced by Backendless. |
Request Body¶
A JSON array containing objects to save.
Return Value¶
The API returns a JSON array of object IDs for the objects created in the database. The order of the objectId
values in the response matches the order of the objects in the request.
The Backendless server implementation enforces the following rules:
Rules |
---|
All objects in the request must be of the same type. |
Objects in the request may have different set of properties. A property in the request body is ignored, if a column does not exist in the table. |
Objects in the request may have a unique objectId value that is not used in the database. |
Maximum number of objects in a single request is 100 for Backendless Cloud. It is configurable for Backendless Pro and Managed Backendless. |
A request will be rejected by the server, if there is no Create permission granted to the user identity/roles associated with the request. |
Codeless Reference¶
where:
Argument | Description |
---|---|
table name |
Name of the data table where new records must be saved. |
objects |
Must be a list containing JSON objects to save in the database. Object properties must match the names of the table columns. The object must not have the objectId property. |
Return created objectIds |
Optional parameter. When this option is selected, the operation returns a list containing one or more objectId values , depending on the number of saved objects. |
Returns a list containing one or more objectId
values, depending on the number of saved objects.
Consider the following structure of the data table called employees
:
For demonstration purposes, the data table presented above has three custom columns: name
, position
, and phoneNumber
. The objectId
is a system column that contains unique identifiers of the records in the table. When a new record is saved to the table, the system assigns a unique objectId
to it. The objectid
is used in various operations as an access point to a specific record.
The example below saves two new JSON objects to the employees
data table:
The result of this operation will look as shown below after the Codeless logic runs:
The operation described above has returned a list containing two objectId
values associated with the newly created records: