Batch request - Dynamics CRM

前端 未结 1 388
情歌与酒
情歌与酒 2021-01-16 20:03

All,

I am trying to implement a batch request to Dynamics CRM with the following source code:

public async Task HttpPatchC         


        
相关标签:
1条回答
  • 2021-01-16 20:10

    I think your request is wrong. You must build the request Body EXACTLY like defined by Microsoft

    This means the Blank lines must be there at the right place all the attributes must exist in the body (like "--changeset_XXX" for example) and as I see you dont meet this requirements.

    I just build a Request in Postman against my CRM and it worked:


    URL

    https://yourTenant.api.crm.dynamics.com/api/data/v8.0/$batch
    

    Headers

    OData-MaxVersion:4.0
    OData-Version:4.0
    Accept:application/json
    Authorization:Bearer aVeryLongStringTokenHere
    Content-Type: multipart/mixed;boundary=batch_1234567
    

    Body

    --batch_1234567
    Content-Type:multipart/mixed;boundary=changeset_555666
    
    --changeset_555666
    Content-Type:application/http
    Content-Transfer-Encoding:binary
    Content-ID:1
    
    POST https://yourTenant.api.crm.dynamics.com/api/data/v8.0/accounts HTTP/1.1
    Content-Type:application/json;type=entry
    
    {name: 'BatchJobTest788'}
    --changeset_555666
    Content-Type:application/http
    Content-Transfer-Encoding:binary
    Content-ID:2
    
    POST https://yourTenant.api.crm.dynamics.com/api/data/v8.0/accounts HTTP/1.1
    Content-Type:application/json;type=entry
    
    {new_name: 'BatchJobTest348'}
    --changeset_555666--
    --batch_1234567--
    

    Additional Remarks:

    • The Content-Type of your Header holds your BatchId
    • The Content-Type of your Batch holds your ChangesetId (if it is a change to data)
    • Before starting to programm REST calls try to define them in a REST tool like POSTMAN and make them work. Then build the working request in your code.
    • Here a good explanation-source for the batching in CRM
    0 讨论(0)
提交回复
热议问题