Using Dynamics 365 Business Central APIs in Microsoft Graph

2 days ago Microsoft has announced the availability of Dynamics 365 Business Central APIs in Microsoft Graph. Microsoft Graph is an interesting platform that permits you to have a unique gateway for REST APIs that spans across multiple Microsoft services (I’ve talked about it some days ago in my post about the interaction with Teams).

MSGraph.png

Dynamics 365 Business Central is now one of the available endpoints in Microsoft Graph and I think this is a great way (and alternative to standard APIs) for interacting with the platform.

To work with Dynamics 365 Business Central in Microsoft Graph, you first need to change your D365BC user’s permission in Graph and then enable the Financials.ReadWrite.All permission scope. Here I’m using the Graph Explorer tool:

D365BCGraphAPI_01.jpg

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

For example, to retrieve the available companies in your Dynamics 365 Business Central tenant, you need to send a GET http request to the following URL:

https://graph.microsoft.com/beta/financials/companies

D365BCGraphAPI_02

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

For example, to retrieve the list of Customers for the selected company (CRONUS IT in my case), you need to send a GET http request to the following URL:

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

and you’ll have as response a JSON content that contains the list of all your customers:

D365BCGraphAPI_03.jpg

You can then perform other queries inside your Dynamics 365 Business Central tenant. For example, to retrieve the General Ledger Entries for a given company ordered by Posting Date descending, you can perform a GET http request to the following URL:

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

D365BCGraphAPI_04.jpg

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

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

D365BCGraphAPI_05.jpg

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

To create a Customer record in a given company with the desired Currency Code set as USD, you need to send a POST http request to the following endpoint (by setting also the Content-type as application/json):

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

The request body of this POST request must be a JSON content with the customer’s details to create, like the following:

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

This is the response (full JSON of the created Customer record):

D365BCGraphAPI_06.jpg

and this is your new Customer in Dynamics 365 Business Central:

D365BCGraphAPI_07

Having Dynamics 365 Business Central native APIs in Microsoft Graph is a great feature and it opens the platform to a complete integration with all the Microsoft’s ecosystem.

The available Dynamics 365 Business Central APIs in Microsoft Graph are actually listed here. Consider them as a BETA, they will be improved for sure in the upcoming future.

What I would like to have “out of the box” as APIs for Dynamics 365 Business Central in Microsoft Graph and that actually we don’t have are APIs for:

  • Reading and creating Sales Documents
  • Reading and creating Purchase Documents
  • Retrieving Item Ledger Entries
  • Retrieving Warehouse Entries
  • Reading and creating Warehouse documents
  • Reading and creating Jobs
  • Reading and creating Sales and Purchase Prices

These are often data that we need to bulk insert in the ERP or that we have to load from external sources. Having native Microsoft Graph APIs for these entities could be extremely useful (as someone of you already knows, I would like to totally replace Rapidstart packages that are too slow for massive data import scenarios). There’s an opened idea here if you want to support.

This is just the beginning… 🙂

3 Comments

  1. hello Stefano,
    hope you doing well, I need your help in one task. Right now I am working on retrieve all of the files names from folder of SharePoint. and here is the API of Microsoft: “http://site url/_api/web/GetFolderByServerRelativeUrl(‘/Folder Name’)/Files”

    I tried to call this API https://XXXXXX.sharepoint.com/sites/Fileupload/_api/web/GetFolderByServerRelativeUrl('/Files‘)/Files through POSTMAN but it gives me error as below.

    Status: 403
    “Access denied. You do not have permission to perform this action or access this resource.”

    So, Can you tell me what i can do to solve this error?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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