Run APIs in Batches
/api/core/Batch/execute
Include any required parameters and request body properties for the specified endpoint in the data or dynamicData properties. You do not need to specify whether a parameter belongs in the path, query, or body. You can use data for properties with static values, or you can use dynamicData for properties with both static values and values that are defined dynamically based on responses to earlier requests in the same batch. You can use both data and dynamicData in the same object, or for simplicity, you can include all properties in dynamicData. As best practices, do not repeat the same property in both data and dynamicData, and put each nested array in only one location.
For example, the Update a Device endpoint requires:
- An id parameter in the path. You can specify this in data or dynamicData if you know the event ID, or dynamicData to dynamically determine the event ID based on the response to an earlier request in the same batch.
- A request body with the properties that you want to update from the deviceDevices schema. Specify properties with static values in data or dynamicData and specify properties with dynamic values in dynamicData. If, for example, you want to include dynamically defined and static values in the nested MetaData array, you can include the entire MetaData array, with both static and dynamic values, in dynamicData.
See the descriptions of each endpoint in this document for required and optional parameters.
You can optionally use the following properties to string requests together:
- response: Defines local variables, with names that you determine, to store values from API response fields. Include these variables in the dynamicData properties of later actions in the same batch.
- dynamicData: Defines request query, path, or body parameters with values that are dynamically supplied by the variables defined in earlier responses in the same batch.
- forEach: Makes the same request (specified in the api and method properties) for each element in an array. Usually you define one Actions array item with a GET request to get a list of resources, then define another Actions array item that includes forEach to make the same PATCH, PUT, or DELETE request for each resource in the list. The API performs multiple actions based on the second object, so you do not have to write separate objects for each resource.
You can use batch files to automate configurations and reproduce settings in different environments. For example, if you want the same data in separate environments for testing or bug troubleshooting, you can use the same batch file to create the same resources in both places.
Request
There are no request parameters for this operation.
- application/json
object
-
Actions: array
Actions
The array of objects with API requests defined in them.
array
object
-
api: string
The API endpoint to run a request against.Example:
broker/services
-
data: object
data
Parameters with static values to use in the request path, query, or body.
-
dynamicData: object
dynamicData
Parameters with dynamic values to use in the path, query, or body. These parameters are dynamically defined as the batch is run. You use variables created in the response property of a previous request in the dynamicData of subsequent requests in the batch. For example, if a previous request in the batch saved a server ID returned in its response, you could use that server ID in the body, path, or query of the subsequent request.
-
forEach: object
forEach
An object defining a loop over an array. For each item in the array variable referenced in the from property:
- Store the value in a new variable named in the varName property
- Run the API request, using the new variable, referenced in the dynamicData property.
-
method: string
The method of the API to call. Allowed values are:
- create: For POST requests.
- read: For GET requests.
- update: For PATCH or PUT requests.
- delete: For DELETE requests.
Example:read
-
response: array
response
The array of field-value pairs to populate with values from the API response. For example, you could save the server ID returned in the response of a request to get server details based on the web FQDN, and use the server ID in the dynamicData of a subsequent request in the batch.
object
{
"limit":1,
"filter":{
"property":"ServerHostFQDN",
"value":"host.example.com",
"operator":"eq"
}
}
object
{
"filter":{
"property":"ServerID",
"value":"$ServerID",
"operator":"eq"
}
}
object
- Store the value in a new variable named in the varName property
- Run the API request, using the new variable, referenced in the dynamicData property.
-
from: string
The name of a variable defined in the response property of a previous API request in the same batch. This variable contains the array to run the request on.Example:
DeviceIDList
-
varName: string
The name of a new variable to store the value from each entry in the array referenced in the from property. Use this variable in the dynamicData property for the current action. The value is updated dynamically as the loop works through each item in the array.Example:
DeviceID
array
object
-
fieldName: string
The name of the field from the response whose values should be stored in the variable. This must match a field in the response. For example, if the response contains a list of devices, and you want to save the device IDs to use in another request, use DeviceID.Example:
DeviceID
-
varName: string
The name of the variable to store response values in for use in later requests in the same batch. Choose a simple, logical name. For example, if the response contains a list of devices, and you want to save the device IDs to use in another request, you could call this DeviceIDList.Example:
DeviceIDList
-
varType: string
Allowed Values:
[ "single", "array" ]
Whether the variable contains a list of values (array) or a single value (single). For example, if the response contains a list of devices, and you want to save all of the device IDs to use in another request with a forEach loop, use array. If the response contains a single device, use single.Example:array
Response
- application/json
200 Response
-
object
SuccessfulGetOperation
The response body for a successful get operation.
-
object
type
object
-
message: string
The response message.Example:
Loaded 1 entries
-
success: boolean
Whether the operation was a success (true) or a failure (false).Example:
true
object
-
api: string
The API endpoint from which the response is returned.Example:
/broker/services
-
method: string
The method of the API that was called.Example:
read
-
request: object
request
An object that contains the combined properties from both data and dynamicData that were sent in the request body. If data and dynamicData contain the same keys, the values are combined into an array. Any variables referenced in the request are replaced by their actual values in the response. In the example, ApplicationConfig came from data in the request, id came from dynamicData, and the value of id was dynamically updated from a variable to an actual value.
-
response: object
response
The response object from the API.
object
{
"ApplicationConfig":{
"BrokerApplicationConfigTypeID":2,
"BrokerApplicationConfigName":"LogLevel",
"BrokerApplicationConfigValue":4,
"Required":1
},
"id":1234
}
object
-
data: object
data
The response body.
-
message: string
The response message.Example:
Updated record
-
success: boolean
Whether the operation was a success (true) or a failure (false).Example:
true
{
"success":true,
"message":"Updated record",
"data":{
"ApplicationConfig":{
"BrokerApplicationConfigTypeID":2,
"BrokerApplicationConfigName":"LogLevel",
"BrokerApplicationConfigValue":4,
"Required":1
},
"id":1234
}
}
object
{
"ApplicationConfig":{
"BrokerApplicationConfigTypeID":2,
"BrokerApplicationConfigName":"LogLevel",
"BrokerApplicationConfigValue":4,
"Required":1
},
"id":1234
}
Default Response
object
-
errors: array
errors
The list of errors reported. Validation errors will be keyed by record field.
-
message: string
The response message.Example:
Exception thrown
-
success: boolean
Whether the operation was a success (true) or a failure (false).Example:
false
array
-
Array of:
object items
An error.
object
Examples
The following examples show how to make API requests in batches. You create a JSON document to contain the requests and pass it to the core/Batch/execute endpoint as the body for a POST request.
You can submit a request using cURL or an API client. The following example uses cURL:
curl -X POST http://hostFQDN/api/core/Batch/execute -d @batchrequest.json
In the JSON document, you can string requests together to use data from one request in a subsequent request. You do this by saving data returned in a response as variables in the response parameter. You can then use these variables in the subsequent requests. For example, a single batch can contain:
- A request that gets a resource's information based on filters, and saves the resource ID in a variable
- A request that updates the resource using the ID from the variable
You can also use the forEach parameter to make the same request for each element in an array. For example, a single batch can contain:
- A request that gets a list of resources and saves their IDs in an array
- A request that updates each resource in the array.
Using the forEach parameter in the update request prevents you from having to write separate get and update requests for each resource.
Example of Updating Log Level for Broker Services
This example illustrates how to string together multiple API calls to update the log level of all broker services on a particular server. The different parts of the JSON object to use in the request body are shown seperately to explain each individually, then the final example combines them together in the Actions array at the root level of the JSON document.
In the JSON document used as the request body, add the following objects to the Actions array:
- A Get Broker
Servers request to get information about a server running on a specific host and
create a variable to save the server ID returned in the response:
{ "api": "broker/servers", "method": "read", "data": { "limit": 1, "filter": [ { "property": "ServerHostFQDN", "value": "<HostFQDN>", "operator": "eq" } ] }, "response": [ { "varName": "ServerID", "fieldName": "ServerID", "varType": "single" } ] }
The details of the JSON object for this call are:
- api: Use the broker/servers endpoint.
- method: Make a GET request (read).
- data:
- Apply the limit query parameter so that only one resource is returned.
- Apply the filter query parameter so that only the resource with the specified host FQDN is returned.
- response: Save the value of the ServerID field returned in the response as a variable called ServerID.
- A Get Broker
Services request to get a list of all services running on the server retrieved in
the previous call and create a variable array to save the service IDs returned in the
response:
{ "api": "broker/services", "method": "read", "dynamicData": { "filter": [ { "property": "ServerID", "value": "$ServerID", "operator": "eq" } ] }, "response": [ { "varName": "ServiceIDs", "fieldName": "BrokerServiceID", "varType": "array" } ] }
The details of the JSON object for this call are:
- api: Use the broker/services endpoint.
- method: Make a GET request (read).
- dynamicData: Apply the ServerID query parameter, using the value saved in the $ServerID variable from the previous request.
- response: Save the values of the BrokerServiceID fields returned in the response as entries in the ServiceIDs variable array.
- An Update a
Broker Service request to update each service that is running on the server,
using the array of IDs retrieved in the previous
call:
{ "forEach": { "from": "ServiceIDs", "varName": "ServiceID" }, "api": "broker/services", "method": "update", "data": { "ApplicationConfig": [ { "BrokerApplicationConfigTypeID": 2, "BrokerApplicationConfigName": "LogLevel", "BrokerApplicationConfigValue": "4", "Required": 1 } ] }, "dynamicData": { "id": "$ServiceID" } }
The details of the JSON object for this call are:
- forEach: Make the request for each entry in the ServiceIDs array created by the previous call, using the values from the ServiceID variable.
- api: Use the broker/services endpoint.
- method: Make a PUT request (update).
- data: Update the specified fields.
- dynamicData: Use the value of the ServiceID variable for each entry in the id path parameter.
{ "Actions": [ { "api": "broker/servers", "method": "read", "data": { "limit": 1, "filter": [ { "property": "ServerHostFQDN", "value": "<HostFQDN>", "operator": "eq" } ] }, "response": [ { "varName": "ServerID", "fieldName": "ServerID", "varType": "single" } ] }, { "api": "broker/services", "method": "read", "dynamicData": { "filter": [ { "property": "ServerID", "value": "$ServerID", "operator": "eq" } ] }, "response": [ { "varName": "ServiceIDs", "fieldName": "BrokerServiceID", "varType": "array" } ] }, { "forEach": { "from": "ServiceIDs", "varName": "ServiceID" }, "api": "broker/services", "method": "update", "data": { "ApplicationConfig": [ { "BrokerApplicationConfigTypeID": 2, "BrokerApplicationConfigName": "LogLevel", "BrokerApplicationConfigValue": "4", "Required": 1 } ] }, "dynamicData": { "id": "$ServiceID" } } ] }
Example of the Response Body
The batch response body contains one item for each request in the data array.
Within each item, the request property contains all of the properties that were included in data and dynamicData in the request, with any variables replaced by their actual values. The response property contains the response body, including response message and data.
Note:
In this example, the response data objects have been shortened where indicated by ... for simplicity. The full response would include more properties in the data objects and a separate object for each service updated by the forEach parameter. See the documentation of the individual endpoints for a full list of response parameters.{ "success": "true", "message": "Loaded 3 entries", "data": [ { "api": "/broker/servers", "method": "read", "request": { "limit": 1, "filter": [ { "property": "ServerHostFQDN", "value": "<HostFQDN>", "operator": "eq" } ] }, "response": { "success": true, "message": "Loaded 1 entries", "data": [ { "ServerID": "1", "PrimaryServerID": "2", "ServerPlatformName": "EXL8", ... } ] } }, { "api": "/broker/services", "method": "read", "request": { "ServerID": "1" } ] }, "response": { "success": true, "message": "Loaded 10 entries", "data": [ { "BrokerServiceID": "1", "ServerID": "1", "ServerName": "example.com", ... }, { "BrokerServiceID": "2", "ServerID": "1", "ServerName": "example.com", ... }, ... ] } }, { "api": "/broker/services", "method": "update", "request": { "ApplicationConfig": [ { "BrokerApplicationConfigTypeID": 2, "BrokerApplicationConfigName": "LogLevel", "BrokerApplicationConfigValue": "4", "Required": 1 } ], "id": "1" }, "response": { "success": true, "message": "Updated record", "data": [ { "BrokerServiceID": "1", "ServerID": "1", "ServerName": "example.com", ... } ] }, { "api": "/broker/services", "method": "update", "request": { "ApplicationConfig": [ { "BrokerApplicationConfigTypeID": 2, "BrokerApplicationConfigName": "LogLevel", "BrokerApplicationConfigValue": "4", "Required": 1 } ], "id": "2" }, "response": { "success": true, "message": "Updated record", "data": [ { "BrokerServiceID": "2", "ServerID": "1", "ServerName": "example.com", ... } ] }, ... ] }