Batch request examples
The following topics provide examples of different types of batch requests.
Simple batch requests
The most simple batch request consist of default GET subrequests. This involves no query parameters and no request payloads.
For this example, the response will consist of three subresponses. Each subresponse will consist of the default fields for each policy.
{
"requests": [
{
"method": "get",
"path": "/policies/demo_sample:1"
},
{
"method": "get",
"path": "/policies/demo_sample:2"
},
{
"method": "get",
"path": "/policies/demo_sample:3"
}
]
}
Batch requests with query parameters
The following is an example of a batch request with multiple GET subrequests. This example includes query parameters for some of the GETs. As shown in the example, it is possible for some subrequests to use query parameters while others do not. The subrequests that use query parameters can use different query parameters.
The response will consist of three subresponses. The fields in each subresponse will vary based on the query parameters.
{
"requests": [
{
"method": "get",
"path": "/policies/demo_sample:1",
"query": "sort=createdDate"
},
{
"method": "get",
"path": "/policies/demo_sample:2",
"query": "fields=*all"
},
{
"method": "get",
"path": "/policies/demo_sample:3"
}
]
}
Batch requests with request payloads
The following is an example of a batch request with multiple POST subrequests. This example includes request payloads for each subrequest.
In this example, two notes are POSTed to different activities. But it would also be possible to POST each note to the same activity.
{
"requests": [
{
"method": "post",
"path": "/activities/xc:11/notes",
"data":
{
"attributes": {
"body": "Batch note 1"
}
}
},
{
"method": "post",
"path": "/activities/xc:73/notes",
"data":
{
"attributes": {
"body": "Batch note 2"
}
}
}
]
}
Batch requests with distinct operations
Every subrequest in a batch request is distinct from the other subrequests. There is no requirement for any subrequest to share any attribute with any other subrequest. Thus, the following is an example of a batch request with multiple subrequests where each subrequest uses a different operation.
{
"requests": [
{
"method": "post",
"path": "/activities/xc:21/notes"
"body": {
"data": {
"attributes": {
"body": "Batch activity 1",
"subject": "Batch activity 1",
"topic": {
"code": "general",
"name": "General"
}
}
}
}
},
{
"method": "patch",
"path": "/notes/xc:22",
"body": {
"data": {
"attributes": {
"body": "PATCHed note body"
}
}
},
},
{
"method": "delete",
"path": "/notes/xc:23"
},
{
"method": "get",
"path": "/activities/xc:24/notes",
"query": "sort=subject&fields=id,subject"
}
]
}