How to – 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

How to – 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..

Blog posts on 2021 Release Wave 1 – Dynamics 365

Advertisements

RECENT POSTS –

How to – Use RetrieveAttributeChangeHistoryRequest to get audit data for an attribute (Dataverse/ Dynamics 365/ CRM)

We can use RetrieveAttributeChangeHistoryRequest to get the change history of a particular field / attribute of a record. We need to set the Target and the AttributeLogicalName property of the request. AuditDetails records of … Continue reading “How to – Use RetrieveAttributeChangeHistoryRequest to get audit data for an attribute (Dataverse/ Dynamics 365/ CRM)”

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/

Blog posts on 2021 Release Wave 1 – Dynamics 365

Hope it helps..

 

Advertisements
Advertisements

Sample Code – Dynamics 365 Web API / Organization Service


Refer appropriate connection string as required with CrmServiceClient- 

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/xrm-tooling/use-connection-strings-xrm-tooling-connect#connection-string-examples

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 –

How to – change user’s business unit without removing the security roles in Dynamics 365 / PowerApps (EnableOwnershipAcrossBusinessUnits setting)

When we change the user’s business unit, all the current security roles of the users are removed and we need to assign the roles again to the … Continue reading “How to – change user’s business unit without removing the security roles in Dynamics 365 / PowerApps (EnableOwnershipAcrossBusinessUnits setting)”

Modernize Business Units / Matrix data access structure -Record ownership across business units (Preview) in Dynamics 365 / Dataverse

To enable this preview feature, log in to the Power Platform admin center, switch on the Environment >> Settings >> Features >> Record ownership across business units … Continue reading “Modernize Business Units / Matrix data access structure -Record ownership across business units (Preview) in Dynamics 365 / Dataverse”

Fixed – The API version ” is not valid for provider ‘Microsoft.BusinessAppPlatform’ – Action ‘Force_Sync_user’ failed error – Power Automate

Recently while testing a flow we got the below error message The API version ” is not valid for provider ‘Microsoft.BusinessAppPlatform’ The supported list of API versions … Continue reading “Fixed – The API version ” is not valid for provider ‘Microsoft.BusinessAppPlatform’ – Action ‘Force_Sync_user’ failed error – Power Automate”

Loading…

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

Dynamics 365 Sales mobile app (preview)


The new Dynamics 365 Sales mobile app (preview), has been introduced specifically for the field sellers who need quick access and intuitive management of the customer information on the go while travelling / meeting the customers.

Check other posts on 2020 Release Wave 2

To enable the App, navigate to Advanced Settings from the Sales Hub and then to Administration > System Settings > Mobile Client tab
We also need to enable Relevance search on the environment for the mobile app’s search to work.

For iOS

https://go.microsoft.com/fwlink/p/?linkid=2151689

For Android

https://go.microsoft.com/fwlink/p/?linkid=2152008

After installation open the app and sign in

From the list of apps, select the App to be used. Here we clicked on the Sales Hub app.

Below is the home page of the app.

The home page provides quick access to recent contacts and recent records along with reminders and insights.

More on Assistant –

https://docs.microsoft.com/en-us/dynamics365/ai/sales/assistant

The + option allows for the quick creation of Note and Contact records.

The more options allow access to the navigate to other part of the apps – dashboard and the other entities.

Search suggestions provide results while we are typing and grouping of search results to quickly find the information needed.

Other sub grid and form tab improvements in the app –

https://nishantrana.me/2020/09/28/sub-grid-and-form-tabs-improvements-in-power-apps-mobile-app/

The meetings option shows the calendar view and the meetings that are scheduled in the outlook.

We cannot create meetings from the Sales Mobile app.

Get all the details here –

Overview of the Dynamics 365 Sales mobile app

Blog posts on 2021 Release Wave 1 – Dynamics 365

Hope it helps..

 

Recent Posts – 

Loading…

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

%d bloggers like this: