Batch Requests
Issue multiple API requests at once
Combine multiple requests in a single batch and return a consolidated response.
Request format
Batch requests are always issued as POST requests.
A batch request body consists of a single JSON object with one required property: requests. The requests property is an array containing the individual requests. For each of these requests, the following properties are supported:
operation_id: Required The unique operation_id corresponding to the endpoint actionname: Required A name to associate individual responses with requests. In each batch, all requests should have unique names.params: Optional An object containing the query params of the request, if any.body_params: Optional An object containing the body params of the request, if any.path_params: Optional An object containing the path parameters, if any. Since we use theoperation_idto identify the endpoint to call, this property is needed for endpoints containing path parameters. This is used for internal cases mostly. See below for an example of this case.
Batch request example
In the following example, we will fetch both popular and trending events in a single request.
{
"requests": [
{
"operation_id": "get_popular_events",
"name": "1",
"params": {
"count": "10",
"filters": "sport:eq:Soccer"
}
},
{
"operation_id": "get_trending_events",
"name": "2",
"params": {
"to_offset": "10h",
"count": "5"
}
}
]
}Batch request example with path parameters
Assuming that some_operation_id corresponds to an endpoint that contains the id path parameter. To call this action and specify the value 2 for the id path parameter we would do the following.
{
"requests": [
{
"operation_id": "some_operation_id",
"name": "1",
"path_params": {
"id": "2"
}
}
]
}Response format
The status code on a batch response is typically 200 or 400.
Malformed batch request
A 400 status code indicates that the batch request contains an invalid format or semantic errors are present. Some of these errors may be an invalid operation_id or individual request names not being unique.
Valid batch requests
A 200 status code indicates that the batch request is in the correct format. In that case, data property will contain the list of responses. For each response, the following properties will be returned:
body: The body of the response. It will contain the data or the errors or the individual request. Refer to the corresponding endpoint documentation for the available response format of each request.name: The uniquenameof the request this response corresponds to.status_code: Thestatus codeof the individual request.
Individual responses
A 200 status code on the batch response does not indicate that the individual requests inside the batch succeeded. This is why each individual response has a status code as well.
Batch response example
{
"data": [
{
"body": {
"data": [
{
"begin": "2021-11-24T20:00:00Z",
"country": "EUR",
"country_id": null,
"event_id": "SBTE_25177302",
"league": "Champions League",
"league_id": "SBTC3_40685",
"participant_ids": [
"SBTP_246",
"SBTP_258"
],
"participants": [
"Liverpool",
"Porto"
],
"sport": "Football",
"sport_id": "SBTC1_1",
"status": "ended",
"total_bets": 11439
},
...
],
"status": "success"
},
"name": "1",
"status_code": 200
},
{
"body": {
"data": [
{
"begin": "2021-11-25T19:30:00Z",
"country": "EUR",
"country_id": null,
"event_id": "SBTE_25425284",
"league": "Euroleague",
"league_id": "SBTC3_42161",
"participant_ids": [
"SBTP_377739",
"SBTP_643"
],
"participants": [
"Baskonia",
"Real Madrid"
],
"score": 12.7832,
"sport": "Basketball",
"sport_id": "SBTC1_2",
"status": "ended"
},
...
],
"status": "success"
},
"name": "2",
"status_code": 200
}
],
"status": "success"
}Custom client header, the value should be the name of the group the user belongs to
Authentication method to be used, supported values [vaix, iam]. Defaults to vaix
API response
OK
Bad Request
Unauthorized
Forbidden
Not Acceptable
Request Entity Too Large
Unprocessable Entity
Too Early
Internal Server Error
POST /api/batch HTTP/1.1
Host: api.vaix.ai
Authorization: Bearer YOUR_SECRET_TOKEN
x-vaix-client-id: text
Content-Type: application/json
Accept: */*
Content-Length: 98
{
"requests": [
{
"body_params": {},
"name": "text",
"operation_id": "text",
"params": {},
"path_params": {}
}
]
}{
"data": [
{
"body": {
"data": [
{
"begin": "2021-07-02T19:00:00Z",
"confidence": 1,
"country": "International",
"country_id": "sr:category:4",
"event_id": "sr:match:21516115",
"event_type": null,
"league": "Euro Cup",
"league_id": "sr:tournament:1",
"participant_ids": [
"sr:competitor:4717",
"sr:competitor:4707"
],
"participants": [
"Belgium",
"Italy"
],
"sport": "Soccer",
"sport_id": "sr:sport:1",
"status": "closed",
"total_bets": 6663
},
{
"begin": "2021-07-02T16:00:00Z",
"confidence": 0.9004803362353647,
"country": "International",
"country_id": "sr:category:4",
"event_id": "sr:match:21514503",
"event_type": null,
"league": "Euro Cup",
"league_id": "sr:tournament:1",
"participant_ids": [
"sr:competitor:4699",
"sr:competitor:4698"
],
"participants": [
"Switzerland",
"Spain"
],
"sport": "Soccer",
"sport_id": "sr:sport:1",
"status": "closed",
"total_bets": 6000
}
],
"status": "success"
},
"name": "1",
"status_code": 200
},
{
"body": {
"error": "invalid value for count: cannot be less than 1, got -2",
"status": "error"
},
"name": "2",
"status_code": 400
}
],
"status": "success"
}Was this helpful?