Personalized Community is here!
Quickly customize your community to find the content you seek.
Check out the latest Business Central updates!Learn about the key capabilities and features of Dynamics 365 Business Central and experience some of the new features.
Download overview guide | Watch Business Central video
2020 Release Wave 2Discover the latest updates and new features to Dynamics 365 planned through March 2021.
Release overview guides and videos Release Plan | Preview 2020 Release Wave 2 TimelineWatch the 2020 Release Wave 1 virtual launch event
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
With the Spring 18 release of Business Central, Microsoft introduced APIs. There 44 APIs available out-of-the-box.
There are a lot of materials available on the web about APIs for Business Central. Some of them:
Standard APIs are perfect for Connect Apps. If you want to pull/push data to Business Central, but don’t have experience in AL or Business Central architecture – you can still build your app, using any available technology and programming language.
But what if you want to create your own APIs for Business Central?
Now, with October release, that becomes possible, and actually very easy.
With October 18 release of Business Central now it’s possible to create your custom APIs in AL.
Usually, I use https://aka.ms/bcsandbox VM to develop in AL. But at DirectionsNA Microsoft announced support of AL for MacOS!
So, next scenario I will cover from my brand new MacOS Mojave desktop!
For Windows users … continue reading =)
I will create a new AL project, and this will be a hybrid App. It will have Add-on capabilities (internal data structure and UI) and Connect capabilities (exposed API to my tables).
How to create new AL project and download symbols on MacOS
My app will show the list of aeroplanes. Very simple example. I will not show here, how to create new AL table and page – there are tons of material available on the web.
Here is the AL code
After this step, a user will have an opportunity to create/change/delete records in a new table from Business Central UI.
Ok, now we have Add-on app. What’s about Connected App part?
Assume, that you want to provide to the world opportunity to communicate with your App. In my case, I have the list of all aeroplane’s models. So, why not to share that with the world?
First, add an ID field to your table with type GUID.
Assign a value, when you insert the record
From now, any new entry in my table will have a unique ID.
Before continuing, let’s stop in a minute on API endpoints. Endpoint – is a URL, which gives you access to one or many entities inside of Business Central, from outside.
You can access data, through the endpoint, using 2 types of authentication: AAD and Direct (Web service Key).
Depending on authentication type - endpoints URI will differ. In the next examples, I'll use Direct authentication.
Business Central offers out-of-the box API endpoints to the base APIs. Like:
The list of all APIs
The list of companies
The list of items
Endpoints described above, give you access to the data inside production Business Central tenant. They are well described in official docs.
What about API endpoints for the online sandbox tenant? It’s not documented feature (yet). But it’s possible!
https://api.businesscentral.dynamics.com/v1.0/<sandbox tenant id>/sandbox/api/beta
https://api.businesscentral.dynamics.com/v1.0/<sandbox tenant id>/sandbox/api/beta/companies
https://api.businesscentral.dynamics.com/v1.0/<sandbox tenant id>/sandbox/api/beta/companies(<companyId>)/items
Cool, but all endpoints, described above, link us to the base 44 APIs, published by Microsoft.
Is it possible to create our own APIs? And if yes, how to call them both for production and sandbox tenants?
YES! It’s possible!
It’s also not documented feature (or I should improve my Google experience:).
I discovered them during DirectionsNA.
<sandbox tenant id>/sandbox/api/<ApiPublisher>
Great! So how to publish and consume them?
API pages where introduced in NAV2018. All 44 base APIs have own pages with type API.
Let’s create a new API page for aeroplane models. Use snippet for that.
page 50102 "AIR AirplaneModel Entity"
PageType = API;
Caption = 'airplaneModels';
APIPublisher = 'DmitryKatson';
APIVersion = 'beta';
APIGroup = 'airplanes';
EntityName = 'airplaneModel';
EntitySetName = 'airplaneModels';
SourceTable = "AIR Airplane Model";
DelayedInsert = true;
ODataKeyFields = Id;
Caption = 'Id';
ApplicationArea = All;
field(icaoCode; "ICAO Code")
Caption = 'icaoCode';
ApplicationArea = All;
Caption = 'description';
ApplicationArea = All;
trigger OnInsertRecord(BelowxRec: Boolean): Boolean
trigger OnModifyRecord(): Boolean
AirplaneModel: Record "AIR Airplane Model";
IF "ICAO Code" <> AirplaneModel."ICAO Code" THEN BEGIN
Remember some important rules:
You’ve created custom API. But it’s not available yet. We have one final step to be able to consumpt it.
Just publish your app, as usual.
Now let’s test our custom API, using Postman.
From that moment we have our own API on the cloud Business Central!
Let’s save custom endpoint to the variable
urlCustomApiSandbox = https://api.businesscentral.dynamics.com/v1.0/b7268087-f626-4efe-ac43-37bfaafc16d8/sandbox/api/DmitryKatson/airplanes/beta
It took me about 5 minutes to create custom API (and 4 hours to turn it into a blog:)
Do you believe in that? It’s a new future! We can’t even dream about this before, but it’s possible now!
And yes! Once again, I made it without docker, VM, developer licence or whatever. Just my MacOs and VSCode with AL.
Did you know that it’s even possible to extend base APIs! Oh yeee… That’s true! But this is a topic for another blog.
you need to add IF-Match:W/"......./" in the header of the patch request .
Great post Dimitry,
I could use the POST and GET instruction, but when I use the PATCH or DELETE, the system give an error:
"message": "Could not validate the client concurrency token required by the service. Please provide a valid token in the client request."
Do you know what's the problem?
Thanks in advance.
Cool reading. How to enable custom API for own made document type page like the sales order what always contain sales header table and sales line table? I am just little confusing about that.
After failed attempts of getting the API working I download your code and compiled it and uploaded it to a production tenant. But the API doesn't work at all. What's wrong, the request or some switch I need to flip somewhere else?
I tried the following request:
The response I always get is:
"message": "No HTTP resource was found that matches the request URI 'api.businesscentral.dynamics.com/.../airplaneModels;aid=FIN'."
Also tried the following request:
This gives me the same result as "Before Publishing": an Empty response
For correct understanding an Custom API url is build up like, correct?
For the entities within a company you use the following request, right?
It's a shame the documentation on this part of Business Central is so little. API endpoints and how to make your own.
@Jignesh Dhandha: replace the tenant-id in the url with your own tenant-id, I believe that's the way to do it but I don't seem to get it right though.
Very good article to create custom api.
I have one query, when we
system will pop up user name and password so which user name and password we use to test this url in postman.
Thanks for your useful blog. This got me started! :)
Can you explain what you did on "OnModifyRecord()"?
Also, I'm interested in what Dave Saman asked: How to expose fields of an Item Extension through a Custom API?
Great post! Can we create custom api:s on local development? That is, for a local installation of Business Central via docker
I'm trying to extend the existing API's by using a page extension on page 5471, but the fields are not showing on the default endpoints.
Could you point me in the right directions on how to achieve this?
Very good article that got me started. The API has given me some headaches but overall cool feature, I wrote a little article on mibuso on how to create complex types in the API if anyone is interested. forum.mibuso.com/.../nav-2018-api-complex-types
Business Applications communities