{"title":"Using OData transactional $batch requests","url":"https://jonas-paprotka.de/docs/dev-itpro/webservices/use-odata-batch/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/webservices/use-odata-batch, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/webservices/use-odata-batch","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"How to specify that all inner requests in a certain OData $batch request are processed in a transactional way in Business Central.","date":"2023-04-25","meta":{"topic":"concept-article"},"outline":[{"level":1,"title":"Using OData transactional $batch requests","slug":"using-odata-transactional-batch-requests","at":0,"chars":5006},{"level":2,"title":"Enable OData transactional batch behavior","slug":"enable-odata-transactional-batch-behavior","at":721,"chars":540},{"level":2,"title":"Example","slug":"example","at":1261,"chars":71},{"level":2,"title":"Request headers","slug":"request-headers","at":1332,"chars":179},{"level":2,"title":"Request body","slug":"request-body","at":1511,"chars":1785},{"level":2,"title":"Response","slug":"response","at":3296,"chars":1595},{"level":2,"title":"Related information","slug":"related-information","at":4891,"chars":115}],"text":"# Using OData transactional $batch requests\n> APPLIES TO: Business Central 2020 release wave 2 (version 17.1) and later\nIt's possible to specify that all inner requests in a certain OData $batch request are processed in a transactional way. Unless it's invoked commit, if an inner request fails after another request(s) has committed changes, all changes within a batch will be reverted as if the batch request never happened. Transactional $batch requests are useful in scenarios where a single business operation spans multiple requests, because they prevent adverse effects if parts of the operation fail. Also, they can improve performance by reducing the number of requests the client needs to do when errors occur.\n## Enable OData transactional batch behavior\nTo enable transactional batch behavior, include the `Isolation: snapshot` header with the $batch request. The `Isolation: snapshot` header makes the entire batch to run within the same session. If the AL code doesn't invoke COMMIT, then the entire batch runs in the same transaction. Otherwise, for each commit, the transaction is committed, and a new one is started.\nThe ../developer/attributes/devenv-commitbehavior-attribute can be used to override the COMMIT behavior of the invoked method.\n## Example\n```\nPOST businesscentralPrefix/api/v2.0/$batch HTTP/1.1\n```\n## Request headers\nHeader|Value\nAuthorization|Bearer {token}. Required.\nContent-Type|application/json. Required for JSON Batch content.\nAccept|application/json\nIsolation|snapshot\n## Request body\nThe following request body contains three inner requests. The first two requests should execute successfully. The last request includes content that triggers a validation failure, so the request fails.\n```json\n{\n       \"requests\": [\n              {\n                     \"method\": \"PATCH\",\n                     \"url\": \"items(7ce0af2e-0963-460f-9b1f-0014aea3e117)\",\n                     \"headers\": {\n                           \"Company\": \"CRONUS International Ltd.\",\n                           \"Content-Type\": \"application/json\",\n                           \"If-Match\": \"*\"\n                     },\n                     \"body\": {\n                           \"displayName\": \"Touring Bicycle v2\"\n                     }\n              },\n              {\n                     \"method\": \"PATCH\",\n                     \"url\": \"items(7ce0af2e-0963-460f-9b1f-0014aea3e117)/picture(7ce0af2e-0963-460f-9b1f-0014aea3e117)/contentValue\",\n                     \"headers\": {\n                           \"Company\": \"CRONUS International Ltd.\",\n                           \"Content-Type\": \"application/json\",\n                           \"If-Match\": \"*\"\n                     },\n                     \"body\": {\n                           \"value\": \"Picture Blob\"\n                     }\n              },\n              {\n                     \"method\": \"PATCH\",\n                     \"url\": \"items(7ce0af2e-0963-460f-9b1f-0014aea3e117)\",\n                     \"headers\": {\n                           \"Company\": \"CRONUS International Ltd.\",\n                           \"Content-Type\": \"application/json\",\n                           \"If-Match\": \"*\"\n                     },\n                     \"body\": {\n                           \"type\": \"Invalid Type\"\n                     }\n              }\n       ]\n}\n```\n## Response\nThe following response includes successful responses for the first two inner requests, and an error for the last inner request. Because the `Isolation: snapshot` header was present in the batch request, none of the changes made by either of the successful inner requests are applied after completion of the batch request.\n```json\n{\n       \"responses\": [\n              {\n                     \"id\": null,\n                     \"status\": 200,\n                     \"headers\": {\n                           \"content-type\": \"application/json; odata.metadata=minimal\",\n                           \"odata-version\": \"4.0\"\n                     },\n                     \"body\": {\n                           \"displayName\": \"Touring Bicycle v2\",\n                           // ...\n                     }\n              },\n              {\n                     \"id\": null,\n                     \"status\": 204,\n                     \"headers\": {}\n              },\n              {\n                     \"id\": null,\n                     \"status\": 400,\n                     \"headers\": {\n                           \"content-type\": \"application/json; odata.metadata=minimal\",\n                           \"odata-version\": \"4.0\"\n                     },\n                     \"body\": {\n                           \"error\": {\n                                  \"code\": \"Unknown\",\n                                  \"message\": \"'Invalid Type' is not an option. The existing options are: Inventory,Service,Non-Inventory  CorrelationId:  x.\"\n                           }\n                     }\n              }\n       ]\n}\n```\n## Related information\nodata-web-services\nUsing OData to Return-Obtain a JSON Document<return-obtain-json-document>"}