Send multiple requests at once

You can use batch requests with the Merchant API to send multiple requests in a single API call.

A batch request is a single standard HTTP request containing multiple API calls, using the multipart/mixed content type. Within the main HTTP request, each part contains a nested HTTP request.

You can send the batch request to the specified batchPath for the API. The batchPath for the Merchant API beta is batch/{sub-api}/v1beta . You can find the batchPath for other APIs in their discovery documents.

Here are some examples of times you might want to batch your requests:

  • You just started using the API and have a lot of data to upload.
  • A user made changes to data while your application was offline, and your application needs to synchronize local data with the server.

If you have questions about HTTP batching, or if you want to request the ability to send batch requests with our client libraries, submit feedback.

Write a batch request

Here's a sample Merchant API batch request. This request combines a get request to retrieve the regional inventory for a product, and an insert request to update the local inventory for the same product.

You should follow the format of the example exactly:

  1. Use https://merchantapi.googleapis.com/batch/{sub-api}/v1beta as the base URL.
  2. Specify a boundary to separate each nested request, for example:

    -H 'Content-Type: multipart/mixed,boundary=batch_inventory' \

  3. Separate each nested request with the boundary, for example --batch_inventory.

  4. Include Content-Type: application/http at the beginning of each nested request.

  5. (Optional) Use Content-ID to label each nested request with your own ID. For example:

    Content-ID: <get:online:en:US:123456>.

  6. Include a blank line between the header, path and body of each nested request. If the nested request doesn't have a body, leave a blank line before the next boundary.

  7. Don't include the base URL in each individual nested request.

  8. End the main request with a final boundary, for example --batch_inventory–.

curl https://merchantapi.googleapis.com/batch/inventories/v1beta \
-H 'Authorization: Bearer <TOKEN>' \
-H 'Content-Type: multipart/mixed,boundary=batch_inventory' \
--data '
--batch_inventory
Content-Type: application/http
Content-ID: <get:online:en:US:123456>

GET /inventories/v1beta/accounts/123/products/online:en:US:123456/regionalInventories

--batch_inventory
Content-Type: application/http
Content-ID: <post:online:en:US:123456>

POST /inventories/v1beta/accounts/123/products/online:en:US:123456/regionalInventories:insert

{
   "region: "123456",
    "price": {
        "amountMicros": "100000000",
        "currencyCode": "USD"
    }
}
--batch_inventory--
'

If you need to execute your calls in a given order, send them separately and wait for the response to the first request before sending the next one.

Read a batch response

Here's an example of an HTTP batch response. The order of the responses might not match the order of the requests. Use the Content-ID to identify the nested request each nested response belongs to. In the responses, each Content-ID is prefixed with response-.

--batch_YCE-jYH0pmDrBIHeHhltcpXIMpk0VTzQ
Content-Type: application/http
Content-ID: <response-get:online:en:US:123456>
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Vary: Origin
Vary: X-Origin
Vary: Referer
{}
--batch_YCE-jYH0pmDrBIHeHhltcpXIMpk0VTzQ
Content-Type: application/http
Content-ID: <response-post:online:en:US:123456>
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Vary: Origin
Vary: X-Origin
Vary: Referer
{
  "name": "accounts/123/products/online:en:US:123456/regionalInventories/123456",
  "region": "123456",
  "price": {
    "amountMicros": "100000000",
    "currencyCode": "USD"
  }
}
--batch_YCE-jYH0pmDrBIHeHhltcpXIMpk0VTzQ--
'