jsonapidynamics-365dynamics-business-centralhttp-accept-header

Dynamic 365 API only returns XML despite Request for JSON


I am using Postman to query a Dynamics 365 Business Central (BC) API. The API is returning XML and I am trying to get it to return JSON. The Microsoft page that gives an example shows the response as being in JSON format.

Image from Microsoft's Getting Started Developing Connect Apps for Dynamics 365 Business Central

I tried added my own Request header to denote that I would like JSON returned

enter image description here

Postman says that by adding my own "Accept" Request header it will override the one that is auto-generated

enter image description here

Even so I tried sending the request with the auto-generated "Accept" header disabled and enabled. This is the response ...

enter image description here

Am I requesting JSON the proper way for a REST endpoint? Microsoft's example seems to indicate that JSON can be returned yet I am only able to get XML back as shown below (just a fragment)

enter image description here


Solution

  • There are two different endpoints you are talking about, $metadata which generates the whole CSDL schema in xml format, whereas <endpoint>/companies fetches the data in JSON format.

    This can be tested in browser simply pasting these URLs.

    https://api.businesscentral.dynamics.com/v2.0/environment name/api/v2.0/$metadata
    
    https://api.businesscentral.dynamics.com/v2.0/environment name/api/v2.0/companies
    

    Note: Pls test it. I don’t have experience with Dynamics BC, but I managed to get these from docs with the idea of my Dynamics CRM experience :)