Hi, In previous post you have learned on how to setup AAD Authentication in Business Central . In those post , we tested using postman on accessing the API including getting the OAuth Token. But let say if you have a scenario where need to integrate between Dynamics NAV and Business Central how do you get the oauth token for the Authentication . In this post i will show you on how to do that.
Our scenario will be machine to machine let say using Job queue so in this case we will be using Credentials Flow. You can learn more about it on here:
In NAV , you can use HttpWebRequestMgt to make the web service call. What you need to take note is Content Type must be using Form-Urlencoded and the request must be in Stream not a text .
Parameter you need to take note :
TokenURL : https://login.windows.net/YourTenantDomain/oauth2/token
ClientID : Your APP ClientID
ClientSecret : Your APP Client Secret
Resource : https://api.businesscentral.dynamics.com
Sample Code is below :
If your request is correct , you should be getting JSON response including the access_token like below:
For the code for Business Central, you can download it from here :