Why call the CRM Web APIs directly?
The main reason is that the Dynamics 365 connector provides only the following actions:- Create a new record
- Update record
- Delete a record
- Get record
- List records
Authentication Approach
For this blog, we will be using the single tenant server-to-server (S2S) authentication. The best part of using this approach is silent authentication, instead of redirecting the application to the Microsoft login page. Secondly, we can use the “application user” (integration user) to connect to CRM, which does not need a user license, instead of a real user. We can assign the minimum privilege security role to this account as a best practice.Registering your app to access D365 and creating an application user
Please follow the linked article to register your Logic App in Azure AD and create an application user in D365.https://msdn.microsoft.com/en-us/library/mt790170.aspx
The article’s heading is Use Multi-Tenant Server to Server authentication, but the steps are exactly the same for single tenant.
Creating a Logic App
We will be using the clientid (applicationid in Azure AD) and secret-key to get the authentication token from Azure AD, and use that token to make a Web API call.The Logic App we are creating for this blog is very simple and has 4 steps.
Step1
This is an HTTP trigger that can be called from the external application to trigger the Logic App. This is empty for this exercise, but will be used to pass the information to the Logic App from external data sources in future blogs.Step 2
This is the main step. I used an HTTP action to call Azure AD for the authentication token.- URI- It is an Azure AD authentication URL to get the authorisation token. The guid in the URL is the tenant ID that you can get from the Azure AD’s properties.
- Headers- I used Fiddler to capture the request and retrieve the headers.
- Body – In the body I am providing the grant_type, clientid, client_secret and resources values. I got some help from https://alexanderdevelopment.net for this. He was using the grant_type of password and providing the CRM user and password in the body.
- Authentication – it is set to none. I tried to use Oauth 2.0 for authentication and provide the required values, but it never really worked.
Step 3
This step is simply using a JSON parser action to parse the output of Step 2 to use in Step 4.Step 4
This is the final step that uses an HTTP action to make a CRM Web API call.Method- I am using a GET method.
URI – The CRM Web API URL. I am using the GET method to retrieve the top 2 Accounts.
Headers – Most of the headers are taken from sample requests from Microsoft websites. The most important of them is Authorization. It is set to the Bearer access_token retrieved in Step 2.
Run the app
Run the app manually. If you get all green ticks then it means everything is working as expected. Double click on the steps to check the input and output of the step.The following screen shots display the input and output of the HTTP-GetToken and HTTP-Call CRM API steps.
Hi, I am trying to do the same approach which you have mentioned above. I am able to get the access token through postman , but with the same parameters i am using it in Logic app, There I am getting unauthorized error. Please let me know if i am missing something.
ReplyDeleteHi Amreek,
ReplyDeletePlease let me know if you need more details from my end.
Thanks,
Manikandan.G
Hi Amreek,
ReplyDeleteI am using the same approach which you have mentioned above to get the Azure AD access token, able to get the access token through Postman but from logic app I am getting Unauthorized error.
Let me know if you need more details on this.
Please help me on this.
Thanks,
Manikandan.G
It’s interesting to read content. nice pos.
ReplyDeleteMicrosoft Dynamics AX Online Training
Hey, Cool Interesting and Amazing article, the way you describe your points is very awesome.
ReplyDeleteMicrosoft Dynamics Navision
Microsoft Dynamics ERP
Microsoft Dynamics Navision
Microsoft Dynamics 365
Hey i found your aticle amazing well written, the way you describe your points is very awesome.
ReplyDeleteMicrosoft Dynamics Navision
Microsoft Dynamics Navision
Microsoft Dynamics Navision
Microsoft Dynamics Navision
Microsoft Dynamics Navision
Microsoft Dynamics Navision
Microsoft Dynamics Navision
A trader bought a car at 20% discount on its original price. He sold it at a 40% increase on the price he bought it. What percent of profit did he make on the original price?
ReplyDeleteHack TP link wifi
How to Hack Mobile Hotspot
A trader bought a car at 20 discount
VCB Breaker Rating Calculation
100 Python Interview Questions and Answers PDF free download
jsondecodeerror: extra data
Resume for Computer Science Student Fresher
TP link Hack
max integer javascript
good .........very useful
ReplyDeletefresher-marketing-resume-sample
front-end-developer-resume-sample
full-stack-developer-resume-samples
fund-accountant-resume-samples
general-ledger-accountant-resume-sample
government-jobs-resume
hadoop-developer-sample-resume
hadoop-developer-sample-resume
hardware-and-networking-resume-samples
hardware-engineer-resume-sample
Thank you for the great post.
ReplyDeleteCloud-based Call Center Philippines