Working with Dynamics 365 Business Central APIs in Microsoft Graph

Microsoft Graph (https://graph.microsoft.io/) is an interesting platform that provides a unique gateway for RESTful APIs that spans multiple Microsoft services. Dynamics 365 Business Central is now one of the endpoints available in Microsoft Graph.

To work with Dynamics 365 Business Central in Graph, you first need to change your Dynamics 365 Business Central user's permission in Graph and then enable the Financials.ReadWrite.All permission scope. You can do that by using the Graph Explorer tool:

After setting the permissions, you can start using the Dynamics 365 Business Central APIs available in Graph (actually, you need to use the BETA API endpoint).

As an example, to retrieve the available companies in your Dynamics 365 Business Central tenant, you need to send an HTTP GET request to https://graph.microsoft.com/beta/financials/companies, as follows:

You can parse this JSON response and retrieve the company's ID, which you will use in all of the next API calls.

To retrieve the list of Customer records for a given company, you need to send an HTTP GET request to the following URL (by passing the company's ID):

https://graph.microsoft.com/beta/financials/companies('80d28ea6-02a3-4ec3-98f7-936c2000c7b3')/customers

As a response, you will get some JSON data with the list of all of your customers:

To retrieve general ledger entries for a given company ordered by descending posting date, you can perform an HTTP GET request to the following URL:

https://graph.microsoft.com/beta/financials/companies('80d28ea6-02a3-4ec3-98f7-936c2000c7b3')/generalLedgerEntries?$orderby=postingDate desc

This is the response received from the API:

To retrieve, for example, the details for a certain Currency (for example, USD), you need to send an HTTP GET request to the following URL:

https://graph.microsoft.com/beta/financials/companies('80d28ea6-02a3-4ec3-98f7-936c2000c7b3')/currencies?$filter=code eq 'USD'

The response retrieved will be like the following:

From this response, we can retrieve the ID of the currency because we can use it later to create a new Customer record in Dynamics 365 Business Central by using Graph APIs.

To create a Customer record in a company with Currency Code set to USD, you need to send an HTTP POST request to the following endpoint and set Content-type to application/json:

https://graph.microsoft.com/beta/financials/companies('80d28ea6-02a3-4ec3-98f7-936c2000c7b3')/customers

The request body of this POST request must be JSON content with the customer's details that we want to create, as in the following:

{
"displayName": "Graph Customer",
"type": "Company",
"address": {
"street": "V.le Kennedy 8",
"city": "Novara",
"state": "IT",
"countryLetterCode": "IT",
"postalCode": "28021"
},
"phoneNumber": "",
"email": "[email protected]",
"website": "",
"currencyId": "12902bb7-4938-41b9-8617-33492bcac8b3",
"currencyCode": "USD",
"blocked": " ",
"overdueAmount": 0
}

As a response, we get some JSON data with the created Customer record:

If you now open Dynamics 365 Business Central, you will see that the new Customer record has been created:

The Dynamics 365 Business Central APIs available in Graph are listed at https://docs.microsoft.com/en-us/graph/api/resources/dynamics-graph-reference?view=graph-rest-beta.

Consider them as beta versions for now, as they will be improved in the future.

We've covered how to use Graph APIs to interact with Dynamics 365 Business Central. In the next section, we'll get an overview of the automation APIs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.34.178