Batch Requests

Issue multiple API requests at once

Issue a batch request

post
/api/batch

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 action

  • name: 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 the operation_id to 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

Valid batch requests

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"
}
Authorizations
AuthorizationstringRequired
Bearer authentication header of the form Bearer <token>.
Header parameters
x-vaix-client-idstringRequired

Custom client header, the value should be the name of the group the user belongs to

x-vaix-authentication-methodstringOptional

Authentication method to be used, supported values [vaix, iam]. Defaults to vaix

Body

API response

Responses
200

OK

application/json
post
/api/batch
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?