How to call CRM WebAPI in Logic Apps
You probably often use web API provide by Azure/Microsoft in your web applications for customized requirements. Normally,
you should follow OAuth 2.0 code authorization flow to acquire the access token for the API in your web application. But
in Logic Apps, the story is different because all the actions of a work flow are executed in the back-end. In this blog,
we will discuss how to consume Azure API in Logic Apps. In our experiment, we will use CRM WebAPI as an example.
Part 1: Register an application in Azure AD.
-
- Log on Azure Classic Portal https://manage.windowsazure.com/
- Open the Active Directory.
- Click on Add button.
- Select "Add an application my organization is developing" on the popup dialog.
- Set the new application properties to:
- Name: CRM OAuth2 Demo (you can use what name you want)
- Type: Web application and/or web API
-
- Click Next button.
- Set the following application properties: (Any urls we can set here I think because we can change them later, just
make sure the validations can be passed.)- Sign-On URL: https://localhost:1234
- APP ID URL: https://alphac25.onmicrosoft.com/crmoauth2demo
- Click Complete button.
- Click Next button.
-
- The new application titled CRM OAuth2 Demo will be added to the list of applications in the selected Azure
Active Directory. - Select the new application titled CRM OAuth2 Demo.
- The Application Configuration Tab is displayed with the Client Id.
- Configure a client secret for the application.
To generate an access token, we need to configure a client secret.
To do this we add a key to the application in Azure AD. Below is a step by step guide to do this.
- The new application titled CRM OAuth2 Demo will be added to the list of applications in the selected Azure
-
- Assign Dynamics CRM permissions to the Demo application
- Continuing from the previous section, on the applications configuration scroll down to the permissions to other
applications section. - Click on the Add application button.
- The permissions to other applications dialog is displayed.
- Select Dynamics CRM Online.
- Click the Add button.
- Click the Complete button (tick in the lower right corner of the dialog).
- Dynamics CRM Online is added to the permissions to other applications list.
- Check the Access CRM Online as organization user permission from the Delegated Permissions drop down list.
- Click save.
- Continuing from the previous section, on the applications configuration scroll down to the permissions to other
- Assign Dynamics CRM permissions to the Demo application
Part 2: Acquire an access token and use it to call CRM WebAPI
-
- Add an action to acquire access token.
Note*: Set Headers: Cache-Control: no-cache Content-Type:
application/x-www-form-urlencoded Set Body: client_id: Client ID from Azure AD client_secret: Client ID from
Azure AD username: username of the crm user password: crm user's password resource: crm url eg: https://alphac25.crm5.dynamics.com grant_type: password
- Add an action to acquire access token.
Here is my test result:
Ray Wang From APAC DSI team.