Ava API Client

Guide

How to send $batch requests to the Business Central API

Updated 21 November 2026

A $batch request packs several API calls into one HTTP request. Business Central runs them in order and sends back one response with a result for each. You use it to cut round trips, to make a group of changes succeed or fail together, and to read several things from the same moment in time.

When a batch is worth it

Each call to Business Central Online costs a network round trip, and the service counts every request against its rate limits. A batch of twenty reads is one request on the wire and one entry in those limits, and it finishes long before twenty separate calls would.

The second reason is harder to get any other way. With an atomicity group, a set of writes either all happen or none of them do. If the third line of a sales order is refused, the first two are rolled back with it, and you are not left with half an order to clean up by hand.

The third is consistency. The Isolation: snapshot header makes every read in the batch see the database as it was when the batch started, so a report built from several entity sets adds up even while other people are posting.

The endpoint

Every API root has a $batch endpoint beside its $metadata:

POST https://api.businesscentral.dynamics.com/v2.0/<tenant-id>/<environment>/api/v2.0/$batch
Authorization: Bearer <access-token>
Content-Type: application/json

Custom API pages have their own: .../api/<publisher>/<group>/<version>/$batch. A batch can only contain requests under the root you sent it to, so one batch cannot mix the standard API with a custom one.

OData also defines an older multipart format, where each request is a MIME part. Business Central accepts it, but the JSON format is easier to write and to read back, and it is the one shown here.

The JSON format

The body is an object with one property, requests, holding an array. Each entry is one request:

PropertyMeaning
idYour own name for the request. It comes back in the response, so you can match results to requests. Must be unique within the batch.
methodGET, POST, PATCH or DELETE.
urlRelative to the API root: companies(…)/customers, not the full address.
headersHeaders for this one request. A write needs Content-Type: application/json; an update or delete needs If-Match.
bodyThe JSON body, as an object, not a string.
atomicityGroupOptional. Requests with the same group name succeed or fail together.

A batch of two reads looks like this:

{
  "requests": [
    {
      "method": "GET",
      "id": "customers",
      "url": "companies(a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1)/customers?$select=number,displayName&$top=5"
    },
    {
      "method": "GET",
      "id": "items",
      "url": "companies(a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1)/items?$select=number,displayName&$top=5"
    }
  ]
}

Query options work inside the url exactly as they do on a normal call. Write them as you would in a browser address bar; the JSON itself does not need them escaped.

Reading the response

A batch that Business Central could read answers 200 OK whatever happened inside it. The outcome of each request is in the responses array:

{
  "responses": [
    {
      "id": "customers",
      "status": 200,
      "headers": { "content-type": "application/json; odata.metadata=minimal" },
      "body": { "value": [ { "number": "10000", "displayName": "Adatum Corporation" } ] }
    },
    {
      "id": "items",
      "status": 404,
      "headers": { "content-type": "application/json" },
      "body": {
        "error": {
          "code": "BadRequest_ResourceNotFound",
          "message": "Resource not found for the segment 'item'."
        }
      }
    }
  ]
}

So check status on every entry, not just the HTTP status of the batch. A 404 or 400 inside the array carries the same error envelope a single call would, and the codes mean the same thing. Business Central API errors explained lists them.

Responses come back in the order of the requests unless you tell Business Central otherwise, and each keeps its id, so matching them is a loop over two arrays.

Writes in a batch

A write inside a batch needs the same headers it would need on its own. That is the detail most often forgotten: there is no Content-Type on the batch that applies to its members, so each POST and PATCH declares its own.

{
  "requests": [
    {
      "method": "POST",
      "id": "new-customer",
      "url": "companies(a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1)/customers",
      "headers": { "Content-Type": "application/json" },
      "body": {
        "displayName": "Contoso Retail",
        "email": "orders@contoso.example"
      }
    },
    {
      "method": "PATCH",
      "id": "rename",
      "url": "companies(a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1)/customers(3bb5b4b6-ea4c-43ca-ba1c-3b69e29a6668)",
      "headers": {
        "Content-Type": "application/json",
        "If-Match": "W/\"JzE5OzEyMzQ1Njc4OTA7Jw==\""
      },
      "body": { "displayName": "Adatum Ltd" }
    }
  ]
}

The PATCH carries its own If-Match with the record's ETag, read in an earlier call. Leave it out and that one entry fails with BadRequest_InvalidToken while the rest of the batch goes ahead. Fixing If-Match and ETag errors explains where the value comes from.

All or nothing: atomicity groups

Give the requests that belong together the same atomicityGroup. Business Central runs the group in one transaction. If any member fails, every member is rolled back, and each of them reports the failure.

Here a sales order is created with its lines, and the customer's salesperson is changed. If the order is refused, the customer is left untouched:

{
  "requests": [
    {
      "method": "POST",
      "id": "order",
      "atomicityGroup": "order-1001",
      "url": "companies(a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1)/salesOrders",
      "headers": { "Content-Type": "application/json" },
      "body": {
        "customerNumber": "10000",
        "orderDate": "2026-11-21",
        "salesOrderLines": [
          { "lineType": "Item", "lineObjectNumber": "1996-S", "quantity": 12 },
          { "lineType": "Item", "lineObjectNumber": "1900-S", "quantity": 4 }
        ]
      }
    },
    {
      "method": "PATCH",
      "id": "customer-note",
      "atomicityGroup": "order-1001",
      "url": "companies(a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1)/customers(3bb5b4b6-ea4c-43ca-ba1c-3b69e29a6668)",
      "headers": {
        "Content-Type": "application/json",
        "If-Match": "W/\"JzE5OzEyMzQ1Njc4OTA7Jw==\""
      },
      "body": { "salespersonCode": "JO" }
    }
  ]
}

The lines go inside the order as a deep insert, because the order's id does not exist until the order is created, and a later request in the same batch has nothing to point at. Microsoft documents deep inserts with sales quotes as the example; test it against your own version before relying on it for orders.

The OData standard also lets a request refer to the result of an earlier one with $<id> in its URL and a dependsOn list. Check whether your Business Central version accepts that before building on it. The deep insert above does not need it.

Two things to know about groups. A failed group reports the same error status on every member, so look at the body of each to find which one caused it. And a group holds locks for as long as it runs, so keep groups small and do not put long reads inside one.

Consistent reads: the Isolation header

By default each request in a batch reads whatever is committed when it runs, so a batch of several reads can see a record in one list and not in the next. Add one header to the batch itself:

POST .../api/v2.0/$batch
Authorization: Bearer <access-token>
Content-Type: application/json
Isolation: snapshot

Every read then sees the database as it stood when the batch began. Use it for anything that adds up figures across entity sets, such as open orders against stock. It applies to reads; writes still run in order.

Continue on error, or stop

Outside an atomicity group, Business Central keeps going after a failed request and reports each result. If you would rather it stopped at the first failure, so later requests are not attempted, send:

Prefer: odata.continue-on-error=false

Requests after the failure then come back with a status that says they were not run. Pick the behaviour that makes the result easiest to act on: for independent reads, continue; for a sequence where step two only makes sense after step one, stop.

Limits

A batch is one HTTP request, so it counts once against the rate limits, but it is not free. Microsoft caps the number of operations in one batch (100 at the time of writing), and the batch has to finish within the normal request timeout. A batch that is too big is refused as a whole, and one that takes too long fails part way through, which is harder to recover from than a few smaller batches. Fifty operations is a comfortable size for writes; reads can go higher.

Each operation also still has to pass the same permission checks as a single call. A user who cannot update customers cannot do it inside a batch either.

Common errors

What you seeCauseFix
400 on the whole batch, no responses arrayThe batch body itself could not be read: a missing requests property, a duplicate id, or a body given as a string.Check the outer JSON. Each body is an object.
404 BadRequest_ResourceNotFound on one entryThe relative url is wrong, or it starts with a slash or the full address.Write it relative to the API root: companies(…)/customers.
415 on a POST entryNo Content-Type on that entry.Add "Content-Type": "application/json" to its headers.
400 BadRequest_InvalidToken on a PATCHNo If-Match on that entry.Read the record first and send its ETag.
Every member of a group reports the same errorOne of them failed and the group was rolled back.Read each body; the one with a specific message is the cause.
429 on the whole batchRate limited. The batch counts as one request, but you are over the limit anyway.Wait for the time in Retry-After and send it again.

The same thing in Ava

Ava has no separate batch builder. A batch is a POST to $batch with a JSON body, so you write it in the Body tab like any other request, with {{company}} and your other variables inside the URLs. The response is coloured and formatted, so each entry's status and body are easy to pick out, and you can add a test on responses[1].status to catch a failure inside the batch.

When the calls depend on each other, a batch is often the wrong tool anyway: you need the id from step one in step two. For that, put the requests in a folder, add a Capture row that saves id from the first response into a variable, use it in the next request's URL, and run the folder. Each request runs on its own, in order, and the runner shows what passed.

Sources