Web API Enhancements -Dynamics 365

No comments

Hey Techies,

I was going through new What’s new for Developers    and found some thing useful for the developers who uses Web API.

We may need to retrieve entity as soon as you created/updated.

To do this we had to do two operations before

  • Create/Update
  • Retrieve

with this new update we can do the both in one request by specifying header like below

Prefer: return=representation

the above header will retrieve the details of the record which is created/updated.

Request

 POST [Organization URI]/api/data/v8.2/accounts?$select=name,description,accountcategorycode,createdon HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Accept: application/json
Content-Type: application/json; charset=utf-8
Prefer: return=representation

{
    "name": "Test",     
    "description": "This is a test record",
    "accountcategorycode": 1 
}

Response

HTTP/1.1 201 Created
Content-Type: application/json; odata.metadata=minimal
Preference-Applied: return=representation
OData-Version: 4.0

{
    "@odata.context": "[Organization URI]/api/data/v8.2/$metadata#accounts/$entity",
    "@odata.etag": "W/\"536530\"",
    "accountid": "d6f193fc-ce85-e611-80d8-00155d2a68de",
    "accountcategorycode": 1,
    "description": "This is a test record",
    "name": "Test"    
}

 

Hope this will help somebody 🙂

Thank you,

Sreeni

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.