Thursday, February 14, 2019

Dynamics 365 - How to execute batch operations using the Web API (C# code)

The documentation of Dynamics 365 for Customer Engagement apps version 9.x has a section that specifies the details about how to execute batch operations using the Web API at https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/execute-batch-operations-using-web-api.

Unfortunately it does not provide a sample code (in C#) for how to compose the batch request and handle respective response.

So here is the one that I have built for my project:

The SendBatchRequestAsync method has two overloads which can be used for two different scenarios:
  • Execute a batch request that is composed of a list of individual requests, each of them can be in turn a change set, or
  • Execute a list of requests that are grouped into a single change set.
Example 1:

Example 2:

Utility method to create HttpMessageContent:

5 comments:

  1. Really appreciate your efforts. Well done.

    ReplyDelete
  2. I have also created a working code at https://github.com/thucnguyen77/dynamics-365-web-api-batch-request-example.

    ReplyDelete
  3. Thank you very much. you save my time :)

    ReplyDelete
  4. Does this allows multiple files to be uploaded using the batch requests?

    ReplyDelete