• One Response

    Batch Request to Create, Update and Delete records in Dynamics 365 CE

    Batch Request allows us to make multiple API calls within a single API call.  We’re limited to 1000 API calls in a single batch request. The HTTP method only supports POST, PATCH & DELETE in Batch Request.

    In this Blog, We’re calling 3 API calls in a single Batch Request.

    • POST – Create a new Account Record
    • PATCH – Update a Contact Record
    • DELETE – Delete a Contact Record

    Request Body Data:

    --batch_CR
    Content-Type: multipart/mixed;boundary=changeset_EHEE
    
    --changeset_EHEE
    Content-Type: application/http
    Content-Transfer-Encoding:binary
    Content-ID: 1
    
    POST https://dynamicstrial.api.crm.dynamics.com/api/data/v9.1/accounts HTTP/1.1
    Content-Type: application/json;type=entry
    
    {
        "name":"ABC Company",
        "accountnumber":"ABC001",    
    }
    
    --changeset_EHEE
    Content-Type: application/http
    Content-Transfer-Encoding:binary
    Content-ID: 2
    
    PATCH https://dynamicstrial.api.crm.dynamics.com/api/data/v9.1/contacts(d5638eb7-6e87-ed11-81ac-6045bd0061f1) HTTP/1.1
    Content-Type: application/json;type=entry
    
    {
        "firstname":"Young",
        "lastname":"God",
        "emailaddress1":younggod@hotmail.com
    }
    
    --changeset_EHEE
    Content-Type: application/http
    Content-Transfer-Encoding:binary
    Content-ID: 3
    
    DELETE https://dynamicstrial.api.crm.dynamics.com/api/data/v9.1/contacts(a5638eb7-6e87-ed11-81ac-6045bd0061f1) HTTP/1.1
    Content-Type: application/json;type=entry
    
    --changeset_EHEE--
    
    --batch_CR--

    Here are few key things to know :

    • Changeset is a transactional operation which means if any operations fail then all completed operations will be rolled back.
    • Each individual request in the batch request body must start with –batch_<unique identifier>
    • Each individual changeset request operation must start with –changeset_<unique identifier>
    • End of the changeset is set with –changeset_<unique identifier>–
    • End of the batch is set with –batch_<unique identifier>–

    Header:

    OData-MaxVersion:4.0
    OData-Version:4.0
    Accept:application/json
    Content-Type:multipart/mixed;boundary=batch_CR
    Prefer:odata.include-annotations=”*”,return=representation

    NOTE: You must include ” boundary= batch_<unique identifier>” in Content-Type of your header.

    Now click on Send Request.

    This Batch request will Create, Update and Delete record in desired Entity with status “200 OK” in the response body.

    Happy D365ing.

    Reference Links: 

    Execute Batch Operation using Web API

    Compose HTTP requests and handle errors (Microsoft Dataverse for Apps) – Power Apps

    Create Application User In Dynamics CRM

  • Subscribe
    Notify of
    guest
    1 Comment
    Oldest
    Newest Most Voted
    Inline Feedbacks
    View all comments
    trackback

    […] Batch Request to Create, Update and Delete records in Dynamics 365 CE – Nebulaa IT Solutions, […]

WANT QUICK D365 IMPLEMENTATION?

Let started with our D365 Quickstart package and get onboard within 7 days!

I'M INTERESTED!
LATEST POSTS
© Copyright 2024 Nebulaa IT Solutions LLP. All Rights Reserved.
Download
Brochure