Batch Requests
Sometimes you want to perform multiple queries all at once. For example, maybe you need to load a few collections to populate a form. Normally you would need to submit multiple HTTP requests which could be slow.
You POST a map to the /batch endpoint describing the requests you want to submit. The system will process all of your requests at once, and send you back a single result object. The keys of the result will be the same keys you submitted.
Example request using a key-value map of requests to execute in a batch:
1
curl -H "Authorization: key 1:CVRRGQ58QDX8H5B4W4RAJ978Q" \
2
-H "Content-Type: application/json" \
3
-X POST \
4
-d '
5
{
6
"t": {
7
"method": "POST",
8
"url": "/api/tickets",
9
"payload": {
10
"title": "new-ticket"
11
}
12
},
13
"john": "/api/people/1",
14
"img": "/api/people/1/image",
15
"parts": "/api/tickets/5/participants"
16
}
17
'
18
http://example.com/api/v2/batch
Copied!
Example response where each response uses the same key you sent in the request:
1
{
2
"t": {
3
"headers": {
4
"response_code": 201,
5
6
},
7
"data": {
8
"title": "new-ticket"
9
"...": "..."
10
}
11
},
12
"john": {
13
"headers": {
14
"response_code": 404
15
},
16
"data": {
17
"...": "..."
18
}
19
},
20
"...": "..."
21
}
Copied!

POST /batch

Post an object/map (top-level) with the following schema:
Property
Description
Example
Note: KEY
Any arbitrary string you want to use to identify the request.
req_1, department_info, foobar, 12
KEY.url
The API endpoint you want to call. You can also specify query-string params here.
/api/v2/me, /api/v2/tickets?page=2
KEY.method
(optional) GET, POST, DELETE, PUT. Defaults to GET.
GET
KEY.payload
(optional) When using POST/PUT, this is the JSON object you want to submit as the payload itself.
{"foo": "bar"}

GET /batch -- Short GET Syntax

You can also use the short GET syntax to process multiple GET requests all at once by specifying multiple get[KEY]=endpoint_path parameters.
Param
Description
Example
Note: KEY
The 'key' in get[KEY] can be any arbitrary string. It serves the same purpose as KEY above in the POST version of batch.
get[KEY]
The API endpoint to fetch
/api/v2/me, /api/v2/tickets
If you need to specify parameters for any of the get[KEY] calls (for example, to specify a page number), you can use the extended syntax.
Example GET call (note: for purposes of readability, the URL has been split on multiple lines):
1
curl -H "Authorization: key 1:CVRRGQ58QDX8H5B4W4RAJ978Q" \
2
http://example.com/api/v2/batch/api/v2/batch?
3
get[stars]=/api/v2/ticket_stars
4
&get[departments]=/api/v2/ticket_departments
Copied!
Here's an example where the endpoint contains parameters. You need to encode '?' and '&' so they don't get read by the main batch request itself.
1
curl -H "Authorization: key 1:CVRRGQ58QDX8H5B4W4RAJ978Q" \
2
http://example.com/api/v2/batch/api/v2/batch?
3
get[stars]=/api/v2/ticket_stars
4
&get[tickets]=/api/v2/tickets%3Fpage%3D2%26ids%3D1%2C2%2C3%2C4
5
6
# the last line decodes to a URL like:
7
# /api/v2/tickets?page=2&ids=1,2,3,4
Copied!
Last modified 3yr ago