Contents

  • 1 Introduction
  • 2 Register App for CRM / CDS / Dataverse in Azure / Active Directory
  • three Add API Permissions for the App
  • 4 Create Client Surreptitious
  • 5 Associate App User / Gear up Roles in CRM 365 / Dataverse Environs
    • v.1 Method-1 (New way)
    • 5.two Method-ii (Legacy)
  • 6 Find your Organization Id for CRM / Dataverse API calls
  • 7 Using Client ID (i.e. App Id) and Customer Hush-hush to Telephone call Dynamics CRM 365 API / CDS / Dataverse
  • 8 Conclusion
    • 8.i Share this:
    • 8.2 Like this:
    • 8.3 Related

Introduction

In this article, nosotros will show yous footstep by pace arroyo on how to annals an Azure Advert (Agile Directory) app to admission Dynamics CRM 365 API (also same for CDS / Dataverse API). You lot might have heard that Microsoft is deprecating an older way of authenticating (i.e. User ID / Password-based WS-Trust Authentication) on April 2022. Y'all must update your jobs / code to use OAuth 2.0 by April 2022 for whatever CRM related API calls.

In other words rather than User Id / password now you can utilise more secure manner by using OAuth rather than WS-Trust.

Going forrad Microsoft wants you to employ OAuth Token rather than user name/password to call Dynamics CRM 365 API programmatically.

Here is the official link which describes the dates for WS-Trust dusk

Register App for CRM / CDS / Dataverse in Azure / Active Directory

The first pace is to annals your app in Azure Portal nether Agile Directory using the below steps.

  1. Ask your Active Directory Admin to login to Azure Portal and navigate to > Agile Directory Blade.
    OR
    Yous can access it by searching "Azure Agile directory" like below.

    Open Azure Active Directory

    Open Azure Active Directory

  2. Now click on the App Registrations icon and click New App Registration

    New App Registrations under Azure Active Directory

    New App Registrations nether Azure Active Directory

  3. Now adjacent footstep is to give your App name to place easily. Select App is used for your Org merely option (Default) and last enter Redirect URL as beneath (This URL is used for three-legged Authorization Code Grant only). We adopt you lot enter a URL which is OAuth friendly (If yous don't know one Utilize https://zappysys.com/oauth   this is recommended URL if yous working with ZappySys Products)

    Azure AD App Registration - Single / Multi Tenant with Redirect URl (i.e. Call back)

    Azure Ad App Registration – Unmarried / Multi-Tenant with Redirect URL (i.due east. Call dorsum)

  4. Now once App is created you lot can find the Awarding (Client) Id from overview page

    Azure AD App - Find Application / Client Id on overview page

    Azure Advertising App – Find Application / Customer Id on overview folio

Add together API Permissions for the App

Once App is created we need to Add Permission. Basically, we will fix which style of APIs tin can be called by this App and what Actions can exist performed.

For Apps specific to CRM / CDS / Dataverse API, actual app permissions are controlled past User Roles. Check later in this article how to acquaintance one or more Roles to this AD App and so it tin perform certation deportment via API call

  1. To add API Permissions for this Advertisement App click on API Permissions and then click on Add Permission

    Add API Permissions for Azure AD App

    Add API Permissions for Azure Advertizement App

  2. Discover the Dynamics CRM icon and click on it

    Add API Permission for Dynamics CRM API access (Azure AD App)

    Add API Permission for Dynamics CRM API access (Azure AD App)

  3. Now you lot will see only 1 permission for Dynamics CRM (user_impersonation). As we said earlier for Dynamics CRM API security is controlled by User Roles in CRM Portal itself which volition see in the adjacent section. For now, just choose Delegated Permissions,  chequeuser_impersonation and click Add Permissions

    Select API Permissions for Dynamics CRM App (Azure AD App)

    Select API Permissions for Dynamics CRM App (Azure AD App)

  4. Now the last step in Adding API permissions is Grant Admin Consent. If yous are logged in equally an Azure AD User with the correct admin role then no worries else y'all take to ask your Azure AD admin to consent for you so this App can be used to read/write information from CRM.

Create Client Secret

Once App is created next step is to generate a Client Surreptitious. Perform the following steps to create a secret that y'all can use when you call API

  1. Click on Certificates and Secrets and and then New Hugger-mugger

    Azure AD App Create Client Secret / Set Name, Expiration Date

    Azure AD App Create Client Secret / Set Name, Expiration Date

  2. Enter Name for Secret (Yous can give some friendly name if you create multiple secrets to control multiple processes). For instance SecretForTesting, SecretForProduction etc.Select a longer expiration date (i.e. 24 months) if you don't like to change undercover oftentimes in product jobs else choose shorter expiration (i.e. 6 Months or Custom).
  3. One time you Create a Secret brand sure you lot re-create it to a secure location. One time the page is airtight it won't appear again.

    Copy Client Secret for Azure AD App

    Copy Client Secret for Azure Advertisement App

Associate App User / Set Roles in CRM 365 / Dataverse Environment

One time we take App Id and Client Secret nosotros can get to CRM Portal to add together our App as a valid CRM User. And the concluding step will exist to attach some role(s) to App User (Run into Next department).

Method-1 (New way)

Here are the steps to configure User / Security Roles in New business relationship

  1. Click on the below link to login to new portal to manage CRM /Dataverse environment
    https://admin.powerplatform.microsoft.com/environments
  2. Create an Application User using these steps (When prompted choose the same App nosotros created in the previous section)
  3. Now Go to App Users Screen and Edit Security Roles using the below steps

    See available CRM 365 Online / Datavese Environments

    Meet bachelor CRM 365 Online / Datavese Environments

    See available CRM 365 Online / Datavese Application Users

    Encounter bachelor CRM 365 Online / Datavese Application Users

    Edit Security Roles for CRM 365 Online / Datavese Application Users

    Edit Security Roles for CRM 365 Online / Datavese Awarding Users

Method-ii (Legacy)

If you lot prefer to use an older interface (and it's nonetheless bachelor to yous) then you can use the below steps to perform the same affair we described in the previous department.

Notation: Microsoft may soon retire the older interface and force to utilize the previous way only.

  1. To Add our Azure AD App as CRM Application user goto your CRM Portal. Click on Gear icon for Settings > Advanced Settings

    Dynamics CRM Advanced Settings

    Dynamics CRM Advanced Settings

  2. Click on Settings dropdown >Security (Under System Column)

    Dynamics CRM Security Settings (Under Advanced Settings - System)

    Dynamics CRM Security Settings (Under Avant-garde Settings – System)

  3. On the security, screen click on the Users icon

    Manage Dynamics CRM Users / Roles (Add, Edit, Delete)

    Manage Dynamics CRM Users (Add, Edit, Delete)

  4. Once User Screen shows up click on the User Type Dropdown and chooseAwarding Users and click New

    Add new Application User in Dynamics CRM

    Add new Application User in Dynamics CRM

  5. One time User screen shows up. Enter your Application Id (obtained from the Azure Advert App > Overview screen – app created earlier). Click Save and yous will find all other fields auto populates.

    Adding Azure AD App as Dynamics CRM 365 - Application User

    Calculation Azure Ad App equally Dynamics CRM 365 – Awarding User

  6. And the last step is to Attach some CRM Role to the new Awarding User.

    For demo purposes we will choose "System Admin" but for production utilize, you should grant right permission carefully. There are many inbuilt roles you can choose from.

    Associate Security Role(s) for Dynamics CRM Application User

    Acquaintance Security Function(due south) for Dynamics CRM Awarding User

Notice your Organization Id for CRM / Dataverse API calls

Now observe your Org Id before we can call CRM / Dataverse APIs in the next section.

To find your Org Id you lot tin perform the post-obit steps.

Method-1 (New mode – Dataverse Portal)

  1. Go to https://admin.powerplatform.microsoft.com/
  2. Click on the Surroundings you like to access
  3. On the Details, folio copy your Org Id from the Environment URL For example URL might wait like below… Yous just need to re-create the first part (Use this on CRM Connection > Organization Field)
    org8640f7e7 .crm.dynamics.com

    How to find Organization Id for Microsoft Dataverse / CDS / CRM 365 API calls

    How to find Arrangement Id for Microsoft Dataverse / CDS / CRM 365 API calls

Method-2 (Onetime way)

Another way to find your Organization Id is from CRM Portal

If you lot have multiple environments (i.e. Prod, Sandbox) so each environment might have its ain unique URL)

  1. To observe your API Service URL, Click onGear Icon
  2. ChooseAdvanced Settings
  3. Click downwardly arrow onSettings
  4. ClickCustomization
  5. ClickDeveloper Resource Link
  6. On this page now you tin come across various URLs. For examples used in this commodity, we demand to get isService Root URL forSpider web API

How to Find Organization Id / Web API URL / SOAP API Service URL (Unique Environment Instance URL)

How to Find Organization Id / Web API URL / Soap API Service URL (Unique Environs Instance URL)

Using Client ID (i.due east. App Id) and Client Hugger-mugger to Telephone call Dynamics CRM 365 API / CDS / Dataverse

That's it now we are ready to use this App Id and Customer Secret to brand CRM API calls.

To confirm if it's working you lot tin can create a Dynamics CRM Connectedness (using SSIS PowerPack ). Choose OAuth option on Dynamics CRM Connexion

Connect to Dynamics CRM / Dataverse / PowerApps API using OAuth (Client ID /Secret)

Connect to Dynamics CRM / Dataverse / PowerApps API using OAuth (Client ID /Secret)

Conclusion

In this article we saw how to Register Azure AD App to phone call various Microsoft APIs (for this article nosotros focused mainly Dynamics CRM 365 API only)