Batch requests
Send several REST API requests in one call to the batch endpoint, and read each request's status, body and timing from one response.
The batch endpoint runs several REST API requests sent in one call and returns all their responses together. Use it to cut round trips when an integration makes many small reads and writes, or to group requests that belong together.
Endpoint
Send a POST request with a JSON body to https://<instance>.servicely.ai/v1/_batch. Authenticate as for any other REST request.
Servicely runs the requests in the order of the array. Each one behaves exactly as it would on its own, with its own status code. A failing request does not stop the ones after it. The batch itself returns 200 once every request has run.
A body that cannot be parsed as a batch returns 400 with the text Parsing exception: Invalid request format, and no request runs.
Request fields
| Field | Required | Description |
|---|---|---|
id |
Yes | An identifier for the batch, returned in the response. |
requests |
Yes | The array of requests to run. |
include_headers |
No | true returns the response headers of every request. Default false. |
requests[].id |
Yes | A correlation ID that matches the response to the request. |
requests[].url |
Yes | The URL as you would send it on its own, starting at /v1/, with any query parameters. |
requests[].method |
Yes | GET, POST, PUT, PATCH or DELETE. |
requests[].body |
No | The request body as a JSON-encoded string, for POST, PUT and PATCH. |
requests[].include_headers |
No | true returns the response headers of this request only. |
Response fields
| Field | Description |
|---|---|
id |
The batch identifier from the request. |
requests |
One entry per request, in the order they ran. |
requests[].id |
The correlation ID from the request. |
requests[].status_code |
The HTTP status code, as the request would return on its own. |
requests[].status_text |
The reason phrase for the status code. |
requests[].body |
The response body as a JSON-encoded string, or null when the response had none. |
requests[].headers |
The response headers, present only when include_headers is true. |
requests[].execution_time |
Milliseconds the request took. |
Branch on status_code, not status_text. Parse body as JSON to read the records.
Example
This batch reads one user, creates an incident and deletes another incident.
Request
POST /v1/_batch
Content-Type: application/json
{
"id": "batch-0001",
"requests": [
{
"id": "1",
"method": "GET",
"url": "/v1/User?fields=Name&page_size=1"
},
{
"id": "2",
"method": "POST",
"url": "/v1/Incident",
"body": "{\"ShortDescription\":\"Test incident\"}"
},
{
"id": "3",
"method": "DELETE",
"url": "/v1/Incident/00000000000000000000000000000001"
}
]
}
Response
{
"id": "batch-0001",
"requests": [
{
"id": "1",
"status_code": 200,
"status_text": "OK",
"body": "{\"data\":[{\"Name\":\"<user name>\"}]}",
"execution_time": 62
},
{
"id": "2",
"status_code": 200,
"status_text": "OK",
"body": "{\"data\":{\"ShortDescription\":\"Test incident\", ...}}",
"execution_time": 140
},
{
"id": "3",
"status_code": 404,
"status_text": "Not Found",
"body": null,
"execution_time": 9
}
]
}