Manage Dynamics 365 Web API with Azure API Management


Azure API Management is an Azure service to create consistent API gateways for secure, scalable access for back-end applications and services.

Azure API Management consists of 3 main components

  • API Gateway

  • Azure Portal for administration

  • Developer Portal for API documentation

Each API inside Azure API Management contains a reference to the back-end service that implements the API and its operations.

Let us start by creating the Azure API Management resource –

Login to Azure Portal

https://portal.azure.com/

Search for API Management

Provide the appropriate details. (Here we have selected the – Developer tier)

After validation is passed, review and click on Create.

It will take around 30 minutes for the deployment to be finished

After the deployment is successful, we can navigate to it and can find the Gateway URL and Developer portal URL as shown below.

Here we will start with a Blank API.

Specify the display name, name and for Web service URL the URL of Dynamics 365 Web API

Click on +Add operation to add a new operation to the API.

Specify the URL as shown below to fetch all the contacts from Dynamics 365.

The URL of the operation

Right now we will get the 401 error as expected as we have not passed the token expected by the Web API.

Now for the token part for calling the Dynamics 365 API, register the Application in Azure AD, create a new Application User, and assign appropriate security roles to it.

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/authenticate-oauth#connect-as-an-app

Here we would be defining send-request policy, to generate the Token and pass it in the Authorization header to the Dynamis 365 Web API request.

Select the GET operation, navigate to the Design tab and open the policy code editor for inbound processing

Add the send-request and set-header policy to generate and set the bearerToken

Specify the endpoint URL of OAuth token, client id, client secret of the application registered.

"copy code from the end of the post"

Save the change and let us test the API.

We can see the results as expected.

The other things that can be done are to associate the API with Products, specify Subscription, Security, enable Application Insights, Azure Monitor etc.

Specify policies –

https://docs.microsoft.com/en-us/azure/api-management/api-management-policies

References

https://transform365.blog/2020/03/29/azure-api-management-and-dynamics-365-web-api/

https://app.pluralsight.com/library/courses/microsoft-azure-developer-implement-api-management/table-of-contents

Hope it helps..

<policies>
  <inbound>
    <base />
    <send-request mode="new" response-variable-name="bearerToken" timeout="20" ignore-error="true">
      <set-url>https://login.microsoftonline.com/89a735bf-2d85-4a5b-a74a-59656af50f2e/oauth2/token</set-url>
      <set-method>POST</set-method>
      <set-header name="Content-Type" exists-action="override">
        <value>application/x-www-form-urlencoded</value>
      </set-header>
      <set-body>@{ return "client_id=510b66c9-4841-4d3d-8e95-150779adcb3e&resource=https://gcrm.crm.dynamics.com&client_secret=t~6DU7Ma4GZjh.M0Xf7eCizy.E~ME4zy_3&grant_type=client_credentials"; }</set-body>
    </send-request>
    <set-header name="Authorization" exists-action="override">
      <value>
        @("Bearer " + (String)((IResponse)context.Variables["bearerToken"]).Body.As<JObject>()["access_token"])</value>
    </set-header>
  </inbound>
  <backend>
    <base />
  </backend>
  <outbound>
    <base />
  </outbound>
  <on-error>
    <base />
  </on-error>
</policies>
Advertisements

Execute Privilege Name (ExecutePrivilegeName) property of Custom API in Dynamics 365 / Microsoft Dataverse


In the previous post, we created a simple custom API  https://nishantrana.me/2021/01/13/use-custom-api-to-create-custom-messages-in-dynamics-365/

Let us look at its different properties starting with ExecutePrivilegeName

Execute Privilege Name attribute of custom API allows us to specify the name of the privilege that allows execution of the custom API.

Let us update the custom API and specify the privilege name.

For simplification, we have used prvCreateIncident here i.e. Create Case / Incident Privilege.

To get the Privilege name

https://%5Borgname%5D.api.crm.dynamics.com/api/data/v9.1/privileges?$select=name


To test, we updated the security of the Application User to Sales Manager role which doesn’t have the create incident privilege.

Calling the custom API this time as expected gave us the below error

{“error”:{“code”:”0x80040220″,”message”:”Principal user (Id=0f377e29-5545-eb11-a813-000d3a9bf733, type=8, roleCount=1, privilegeCount=727, accessMode=4), is missing prvCreateIncident privilege (Id=6cf9442b-e690-4cad-8b0a-e60464960b93) on OTC=112 for entity ‘incident’. context.Caller=0f377e29-5545-eb11-a813-000d3a9bf733″}}


If we specify an incorrect privilege name we would get the below error and will not be able to save the record.


Hope it helps..


 

Advertisements

Use Custom API to create custom messages in Dynamics 365


Custom API (preview) allows us to define our custom messages that can be called from web services, similar to Custom Actions. Usually, we would be creating custom workflow actions just to create a new message, to which we can hook our plugin, without defining any logic in the workflow. For this scenario or pattern now we can use Custom API instead.

There are different ways of creating a custom API.

  • Through the Maker Portal.
  • Using Web API or Organization Service.
  • Editing the solution files.

The 3 key entities involved here are

  1. CustomAPI
  2. CustomAPIRequestParameter
  3. CustomAPIResponseProperty

Let us try creating a CustomAPI through the maker portal.

Create a new solution, and click on New and select Custom API

Let us start with a very basic custom action.

Unique Name

This will be the name of the message. Should have the prefix same as solution’s publisher. 

Name

The name of the Custom API will show up inside the solution

Display Name

Localized display name of the Custom API

Description  

Localized description of the Custom API 

Binding Type 

  • Value: 0 Label: Global
  • Value: 1 Label: Entity
  • Value: 2 Label: EntityCollection

Bound Entity Logical Name 

Logical name of the entity in case of binding type – Entity and EntityCollection.

Is Function 

  • Value: 0 Label: No
  • Value: 1 Label: Yes

Allowed Custom Processing Step Type 

  • Value: 0 Label: None Meaning: No custom processing steps allowed.
  • Value: 1 Label: Async Only Meaning: Only asynchronous custom processing steps allowed
  • Value: 2 Label: Sync and Async Meaning: No restriction. 3rd party plug-ins can add synchronous logic to change the behavior of the message

Execute Privilege Name


Name of the Privilege that is required for the execution of the Custom API.

Plugin Type

Reference of the plugin registered for the Custom API 

So right now we have a very basic custom API registered of Global type, which doesn’t allow any steps to be registered and doesn’t need any privileges to execute

Let us write a sample plugin and associate with this new message.

Let us register the assembly

Now let us go back to our Custom API record and associate the Plugin registered.

Let us trigger the plugin by calling the Custom API through the Postman.

Let us check the plugin trace log inside Dynamics 365 App.

Get all details here 

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/custom-actions

Hope it helps..

 

 

 

Advertisements

RECENT POSTS –

Export key attribute uniquename for component CustomAPI must start with a valid customization prefix exception while creating Custom Action in Dynamics 365

We might get below error while creating a custom action from the maker portal without specifying the prefix. Unhandled exception: Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault] Message: Export key attribute uniquename for component CustomAPI must start with … Continue reading “Export key attribute uniquename for component CustomAPI must start with a valid customization prefix exception while creating Custom Action in Dynamics 365”

Allowed Custom Processing Step Type (AllowedCustomProcessingStepType) property of Custom API in Dynamics 365 / Microsoft Dataverse

Continuing our previous posts, let us check the AllowedCustomProcessingStepType attribute in this blog post https://nishantrana.me/2021/01/13/use-custom-api-to-create-custom-messages-in-dynamics-365/ https://nishantrana.me/2021/01/14/execute-privilege-name-executeprivilegename-property-of-custom-api-in-dynamics-365-microsoft-dataverse/ Allowed Custom Processing Step Type attribute of custom API allows us to control whether other plugins can be … Continue reading “Allowed Custom Processing Step Type (AllowedCustomProcessingStepType) property of Custom API in Dynamics 365 / Microsoft Dataverse”

Unable to retrieve attribute=businessunitid for entityLogicalName=systemuser exception while creating Application User in Dynamics 365

Recently while trying to add a new application user we got the below error message More on Application User – https://nishantrana.me/2020/12/24/application-user-form-missing-in-dynamics-365/ https://nishantrana.me/2020/12/23/d365-the-user-is-not-a-member-of-the-organization-error-while-connecting-to-ce/ Adding the missing Business Unit field in the form fixed it. Hope … Continue reading “Unable to retrieve attribute=businessunitid for entityLogicalName=systemuser exception while creating Application User in Dynamics 365”

Execute Privilege Name (ExecutePrivilegeName) property of Custom API in Dynamics 365 / Microsoft Dataverse

In the previous post, we created a simple custom API  https://nishantrana.me/2021/01/13/use-custom-api-to-create-custom-messages-in-dynamics-365/ Let us look at its different properties starting with ExecutePrivilegeName Execute Privilege Name attribute of custom API allows us to specify the name … Continue reading “Execute Privilege Name (ExecutePrivilegeName) property of Custom API in Dynamics 365 / Microsoft Dataverse”

Loading…

Something went wrong. Please refresh the page and/or try again.

Improved search experience in Dynamics 365 / PowerApps


To enable the new search experience, we need to turn on the relevance search on that environment.

Login to the admin portal and environments section

https://admin.powerplatform.microsoft.com/environments

Navigate to Settings -> Features and turn on the Relevance Search


This places the search bar in the header, making it easy to access while navigating across different pages.

With Relevance search turned off à

On clicking the search icon à we are navigated to the categorized search page.

The search result for the term “alex” with Relevance Search on–

Even before we can enter our query in the search box, the search box displays the recent terms (seems like max 3) used for search along with recent records (seems like max 6) accessed.

Provides increment search or real-time suggestions while we are tying the search term

Get all the details here

And must-read article on the new search experience à

https://jukkaniiranen.com/2020/11/make-your-power-apps-search-experience-more-relevant/

Hope it helps..

 

 

Advertisements
Advertisements

Migration of Personal views/charts/dashboards with sharing information


Interesting read ..

Phani Rajasekhar

In my previous blog I explained the issues that I faced while POA entity migration. Here I will explain the whole process that I followed to migrate the personal views with sharing information. I used kingsway soft adapter for my migration process.

We have 2 steps to migrate the data

  1. Source CRM –> Intermediate database.
    1. I enabled “Data Export Services” on the source instance to push the data into intermediate database.
    2. Since “userquery” entity is not available in “Data Export Services”, I Designed a simple SSIS Package with source (Dynamics CRM) and destination (OLE DB) components.
    3. We have to impersonate the owner of the personal view in the Dynamics CRM Source component to read this information.
    4. So we have to run this package multiple times based on the user count.

  1. Intermediate database –> Target CRM
    1. Designed 2 more SSIS Packages to push “userquery” and “principalobjectaccess” (share) information to Target CRM…

View original post 147 more words

Sample Code – Dynamics 365 Web API / Organization Service


the connection string parameters

Replace Office 365 authentication with OAuth

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/authenticate-office365-deprecation

Advertisements

Recent Posts –

Loading…

Something went wrong. Please refresh the page and/or try again.