web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Batch request using web api

(0) ShareShare
ReportReport
Posted on by 700

Hi,

We used batch request of web api to retrieve records of multiple entities say suppose accounts and contacts using fetch xml.

We are able to get the response but response is as shown below. Now we need to parse this response and get the separate collection of record for accounts and contacts.

--batchresponse_a5ec534a-1906-4613-ab3c-304cc20c0c5e
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{"@odata.context":""@Microsoft.Dynamics.CRM.totalrecordcount":-1,"@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded":false,"value":[{"@odata.etag":"W/\"3356018\"","fullname":"Della">uat54.crm.dynamics.com/.../$metadata Selestewa","contactid":"f4648fd7-e0ad-e911-a9ad-000d3a37fb92"},{"@odata.etag":"W/\"2159222\"","fullname":"Della Selestewa","contactid":"458f8747-d6a2-e911-a998-000d3a37fbce"}]}
--batchresponse_a5ec534a-1906-4613-ab3c-304cc20c0c5e
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="*"

{"@odata.context":""@Microsoft.Dynamics.CRM.totalrecordcount":-1,"@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded":false,"value":[{"@odata.etag":"W/\"2236328\"","name":"Agin">uat54.crm.dynamics.com/.../$metadata & Sons","accountid":"c1ea7401-e0a2-e911-a99d-000d3a37f80d"}]}
--batchresponse_a5ec534a-1906-4613-ab3c-304cc20c0c5e--

Is any one have solution how can we get separate collection of record for accounts and contacts by parsing above response.

Waiting for your reply.

Thanks!

Balasaheb    

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Partner,

    Since the response is such a text, thus we should parse it manually with our own function.

    My implementation's below:

    I split the whole text into an array with "--batch" as separator, it will be split to 4 array item, our target contents are in item 1 and 2, so I select these items and push them into new array.

    then I observe the actual data inside the batchresponse is between { and }. Hence I substring of the actual data using the function below.

    value.substring(value.indexOf('{'),value.lastIndexOf('}')+1)

    2678.png

    5758.png

    Result:

    7384.png

    Notes:

    I found there is escape character issues in @odata.context value and first contact fullname field Della">uat54, 

    so I modified these 2 places and the text can be parsed as an JSON object:

    004.png

    Perhaps it's a issue when posting text with many characters. 

    You could try execute my code in your environment to test whether it works.

    Regards,

    Clofly

  • Suggested answer
    Balasaheb Profile Picture
    700 on at

    Hi Clofly,

    Thanks for your reply.

    Thanks!

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Partner,

    Did the script work in your environment ?

    And has your problem been solved successfully?

    Please let me know if you have any other question. :)

    Regards,

    Clofly

    Please mark as verified if the answer is helpful, it would be greatly appreciated.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans