Skip to main content
Version: 8.1

Batch request examples

Level: advanced

Batch requests combine multiple HTTP requests by specifying each request as a separate object in the batch request's body. The Creatio database server returns a single HTTP response that contains the responses to each request. Use batch requests to improve Creatio performance.

The batch requests utilize:

  • The POST HTTP method.
  • The $batch parameter.
  • The Content-Type header.

The values of the Content-Type header:

  • application/json – restricts the content the server returns for each request within the batch request to a single type.
  • multipart/mixed – allows you to set unique Content-Type headers for each request in the batch request body.

If one of the requests completes with a 4xx-5xx group response code, the subsequent requests will not be executed. Add the Prefer: continue-on-error header to the main HTTP request to enable the execution of the subsequent requests.

Important

A batch request can contain up to 100 requests.

Batch request (Content-Type: application/json)

POST http://mycreatio.com/0/odata/$batch

Content-Type: application/json; odata=verbose; IEEE754Compatible=true
Accept: application/json
BPMCSRF: OpK/NuJJ1w/SQxmPvwNvfO
ForceUseSession: true

{
"requests": [
{
// Add an object instance to the City collection.
"method": "POST",
"url": "City",
"id": "t3",
"body": {
// Add the Burbank value to the Name field.
"Name": "Burbank"
},
"headers": {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Prefer": "continue-on-error"
}
},
{
// Add an object instance to the City collection.
"method": "POST",
"atomicityGroup": "g1",
"url": "City",
"id": "t3",
"body": {
// Add the 62f9bc01-57cf-4cc7-90bf-8672acc922e3 value to the Id field.
"Id": "62f9bc01-57cf-4cc7-90bf-8672acc922e3",
// Add the Spokane value to the Name field.
"Name": "Spokane"
},
"headers": {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Prefer": "continue-on-error"
}
},
{
// Update the 62f9bc01-57cf-4cc7-90bf-8672acc922e3 id object instance in the City collection.
"method": "PATCH",
"atomicityGroup": "g1",
"url": "City/62f9bc01-57cf-4cc7-90bf-8672acc922e3",
"id": "t2",
"body": {
// Change the value of the Name field to Texas.
"Name": "Texas"
},
"headers": {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Prefer": "continue-on-error"
}
}
]
}

Batch request (Content-Type: application/json and Prefer: continue-on-error)

POST http://mycreatio.com/0/odata/$batch

Content-Type: application/json; odata=verbose; IEEE754Compatible=true
Accept: application/json
BPMCSRF: OpK/NuJJ1w/SQxmPvwNvfO
ForceUseSession: true
Prefer: continue-on-error

{
"requests": [
{
// Add an object instance to the City collection.
"method": "POST",
"url": "City",
"id": "t3",
"body": {
// Add the Burbank value to the Name field.
"Name": "Burbank"
},
"headers": {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Prefer": "continue-on-error"
}
},
{
// Update the 62f9bc01-57cf-4cc7-90bf-8672acc922e3 id object instance in the City collection.
"method": "PATCH",
"atomicityGroup": "g1",
"url": "City/62f9bc01-57cf-4cc7-90bf-8672acc922e2",
"id": "t2",
"body": {
// Change the value of the Name field to Indiana.
"Name": "Indiana"
},
"headers": {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Prefer": "continue-on-error"
}
},
{
// Add an object instance to the City collection.
"method": "POST",
"atomicityGroup": "g1",
"url": "City",
"id": "t3",
"body": {
// Write the 62f9bc01-57cf-4cc7-90bf-8672acc922a1 value to the Id field.
"Id": "62f9bc01-57cf-4cc7-90bf-8672acc922a1",
// Write the Iowa value to the Name field.
"Name": "Iowa"
},
"headers": {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Prefer": "continue-on-error"
}
}
]
}

Batch request (Content-Type: multipart/mixed)

POST http://mycreatio.com/0/odata/$batch

Content-Type: multipart/mixed;boundary=batch_a685-9724-d873; IEEE754Compatible=true
BPMCSRF: OpK/NuJJ1w/SQxmPvwNvfO
ForceUseSession: true

--batch_a685-9724-d873
Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e7e

--changeset_06da-d998-8e7e
Content-Type: application/http
Content-Transfer-Encoding: binary

// Add an object instance to the City collection.
POST City HTTP/1.1
Content-ID: 1
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Content-Type: application/json;odata=verbose

// Write the Gilbert value to the Name field.
{"Name": "Gilbert"}

--changeset_06da-d998-8e7e
Content-Type: application/http
Content-Transfer-Encoding: binary

// Update the 62f9bc01-57cf-4cc7-90bf-8672acc922e2 id object instance in the City collection.
PATCH City/62f9bc01-57cf-4cc7-90bf-8672acc922e2 HTTP/1.1
Content-ID: 2
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Content-Type: application/json;odata=verbose

// Change the value of the Name field to Lincoln.
{"Name": "Lincoln"}

--changeset_06da-d998-8e7e
Content-Type: application/http
Content-Transfer-Encoding: binary

// Delete the 62f9bc01-57cf-4cc7-90bf-8672acc922e2 id object instance from the City collection.
DELETE City/62f9bc01-57cf-4cc7-90bf-8672acc922e2 HTTP/1.1
Content-ID: 3
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Content-Type: application/json;odata=verbose

Batch request (Content-Type: multipart/mixed and different sets of requests)

POST http://mycreatio.com/0/odata/$batch

Content-Type: multipart/mixed;boundary=batch_a685-9724-d873; IEEE754Compatible=true
Accept: application/json
BPMCSRF: OpK/NuJJ1w/SQxmPvwNvfO
ForceUseSession: true

--batch_a685-9724-d873
Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e7e

--changeset_06da-d998-8e7e
Content-Type: application/http
Content-Transfer-Encoding: binary

// Add an object instance to the City collection.
POST City HTTP/1.1
Content-ID: 1
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Content-Type: application/json;odata=verbose

// Write the d6bc67b1-9943-4e47-9aaf-91bf83e9c285 value to the Id field.
// Write the Nebraska value to the Name field.
{"Id": "d6bc67b1-9943-4e47-9aaf-91bf83e9c285", "Name": "Nebraska"}

--batch_a685-9724-d873
Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e71

--changeset_06da-d998-8e71
Content-Type: application/http
Content-Transfer-Encoding: binary

// Add an object instance to the City collection.
POST City HTTP/1.1
Content-ID: 2
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Content-Type: application/json;odata=verbose

// Write the d6bc67b1-9943-4e47-9aaf-91bf83e9c286 value to the Id field.
// Add the Durham value to the Name field.
{"Id": "d6bc67b1-9943-4e47-9aaf-91bf83e9c286", "Name": "Durham"}

Resources

Creatio API documentation