Batch Operations

Perform several operations in a single API call.

A batch operation performs several API calls in a single call.

📘

Batch API Calls Count

When performing a batch operation, the actual number of API calls is the number of calls inside the batch operation. For example, if a batch operation updates 5 objects, it will count as 5 platform API calls.

To execute a batch operation send the following request:

curl -X POST \
-H "Content-Type: application/json" \
-H "X-Appery-Database-Id: <database_id>" \
[-H "X-Appery-Session-Token: <session_token>" \]
-d "<operations_array>" \
https://api.appery.io/rest/1/db/batch

operations_array is a JSON array of objects containing batch operations description. For example:

[
    {
        "method": "<method>",
        "collection": "<collection_name>",
        "_id": "<object_id>",
        "data": <object_data>
    },
    {
        "method": "<method>",
        "collection": "<collection_name>",
        "_id": "<object_id>",
        "data": <object_data>
    },
    ...
]
ParameerDescriptionRequired
methodGET, POST, PUT or DELETE.Yes.
collection_nameDatabase collection name.Yes
object_idObject ID to perform the operation on.Required for GET, PUT or DELETE.
object_dataObject data for the operation.Required for POST or PUT.

The database returns HTTP 200 OK status and JSON array representing results for the operations requested.

If an operation fails on a specific objects, operations on other objects will continue.

The position of the operation result item is the same as the position of the operation description in the request. For example:

[
    {
        "<operation_status>": <operation_result>
    },
    {
        "<operation_status>": <operation_result>
    },
    ...
]
ParameterDescription
operation_statussuccess or error.
operation_resultJSON object representing operation response which is usually returned by a direct service invocation (see Collections REST API for more details), including error responses.

Example

For collection Labels with one custom column name (string):

654

Sample collection.

Batch operation has the following format:
curl -X POST \
-H "Content-Type: application/json" \
-H "X-Appery-Database-Id: 58a59358975a4fa00e0ff50f" \
https://api.appery.io/rest/1/db/batch
-d 
  "[
    {
        "method": "post",
        "collection": "Labels",
        "data": {"name": "nick"}
    },
    {
        "method": "put",
        "collection": "Labels",
        "_id": "58a59386975a4fa00e0ff513",
        "data": {"name": "max updated"}
    },
    {
        "method": "delete",
        "collection": "Labels",
        "_id": "58a59381975a4fa00e0ff512"
    },
    {
        "method": "get",
        "collection": "Labels",
        "_id": "58a59386975a4fa00e0ff513"
    }, 
    {
        "method": "put",
        "collection": "Labels",
        "_id": "000000000000000000000000",
        "data": {"name": "unexisting label with _id 000000000000000000000000"}
    }
]"
[
  {
    "success": {
      "_id": "58a5962d0a975a799b278abd",
      "_createdAt": "2017-02-16 12:08:13.327"
    }
  },
  {
    "success": {
      "_updatedAt": "2017-02-16 12:08:13.337"
    }
  },
  {
    "success": {}
  },
  {
    "success": {
      "_id": "58a59386975a4fa00e0ff513",
      "name": "max updated",
      "_createdAt": "2017-02-16 11:56:54.725",
      "_updatedAt": "2017-02-16 12:08:13.337"
    }
  },
  {
    "error": {
      "code": "DBSU205",
      "description": "Collection 'Labels' doesn't contain object with id 000000000000000000000000."
    }
  }
]