Tag: how to get access token for dynamics crm authentication using OAuth 2.0

CREATE AUTO-NUMBER ATTRIBUTE IN DYNAMICS CRM 365 USING WEB API + Use POSTMAN with CRM Online

With the Dynamics 365 v9, you can add an auto-number attribute for any entity. Currently, you can add the attribute programmatically. There is no user interface to add this type of attribute. 

I have in my other blog showed how you can achieve this using C#(console application) : CREATE AUTO-NUMBER ATTRIBUTE IN DYNAMICS CRM 365 USING ORGANIZATION SERVICE + SIMPLE CONSOLE APPLICATION

In this blog I am going to show you how you can achieve this using a simple WebApi request, By default this blog will also help you to learn and see how you can use postman to connect with dynamics 365 online to perform certain WEBAPI operations as we will be suing postman to fire a web api request.

  1. If you don’t already have POSTMAN, download desktop application here it here : POSTMAN Desktop Client  or simply add a chrome extension : Chrome Extension . In my case I am using a chrome extension. Launch the application and select Action as “POST”:

  2. Enter below URL in the next url section:
    https://%5BOrganizationURL%5D/api/data/v9.1/EntityDefinitions(LogicalName=’EntityLogicalName’)/Attributes/ 
    Enter the correct organization url and entity logical name on which you need to create an auto number field.

  3. Now click on “Headers” and add below:
     
  4. Now click on “Body” tab and select “raw” option:
  5. Enter below Json request in the editor:
     
{
 "AttributeType": "String",
 "AttributeTypeName": {
  "Value": "StringType"
 },
 "Description": {
  "@odata.type": "Microsoft.Dynamics.CRM.Label",
  "LocalizedLabels": [
   {
    "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
    "Label": "Serial Number of the widget.",
    "LanguageCode": 1033
   }
  ]
 },
 "DisplayName": {
  "@odata.type": "Microsoft.Dynamics.CRM.Label",
  "LocalizedLabels": [
   {
    "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
    "Label": "Serial Number",
    "LanguageCode": 1033
   }
  ]
 },
 "RequiredLevel": {
  "Value": "None",
  "CanBeChanged": true,
  "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
 },
 "SchemaName": "new_AutoNumber",
 "AutoNumberFormat": "WID-{SEQNUM:5}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmmss}",
 "@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",
 "FormatName": {
  "Value": "Text"
 },
 "MaxLength": 100
}

       6. change the “SchemaName” of the field as per your need in my case its “new_AutoNumber” and also you can change the AutoNumberFormat as we discussed in the last post : : CREATE AUTO-NUMBER ATTRIBUTE IN DYNAMICS CRM 365 USING ORGANIZATION SERVICE + SIMPLE CONSOLE APPLICATION

    7. Okay its starting to look really good. but here comes the important part how do we setup the authentication – to do this click on “Authorization” Tab and select Type as “OAuth 2.0”:
    

    8. When you select Type as “OAuth 2.0” you have option to “Generate Access Token”

      

    9.Click on Generate New Access Token:
       

    10. Enter Details as below : 

      Token Name : Desires Name i.e dynamics crm Online

      AuthURLhttps://login.windows.net/common/oauth2/authorize?resource=%5Byour dynamics crm plain URL i,e https://passion4dynamicscrm.crm8.dynamics.com%5D

     Access Token URL : https://login.microsoftonline.com/common/oauth2/token 

     Client ID : follow this blog i have created to get client id of your dynamics CRM : REGISTER DYNAMICS CRM APP WITH AZURE FOR OAUTH 2.0 AUTHENTICATION

   11. Now click on Request Access token, you will be asked to login to your dynamics CRM, after successful login you will have a screen below:

     Select the token which we have setup and change “Add token to” to Header and click on “Use Token” which will add this to headers.

   

    13.  we are all set to execute our request , so click on “Send” , if everything was setup properly you will get success with no response:
     

   14. Open you dynamics CRM and navigate to Settings > Customizations > Customize the system > entity name > fields and notice the field has been created:
       

   15. Go ahead and put this field on the form and create some records.

     

   There you go! I hope this helps! Please feel free to let me know if you face any issues during this operation.

Register Dynamics CRM App With Azure for OAuth 2.0 Authentication

In this blog, I am going to take you through step step process of registering dynamics CRM application with azure.

Why do we even need to do that?

well, If you ever need to use Dynamics CRM OAuth authentication method to be able to connect to dynamics crm using Web API, you are going to need this. follow below steps:

  1. Login to  Azure Portal  ( Use the same credentials as your dynamics crm, if it asks you to sign up and setup trial, you can do that)
  2. Once you have logged in, Navigate to the option “Azure Active Directory” and click on “App registration:

  3. Click on “New application registration”

  4. Add the name of the application and select the Application type as “Native”:

  5. In the URL field enter the URL using which you need to obtain the OAuth authentication token in response to the request from that URL ( In my case I am going to use a POSTMAN call back url : https://www.getpostman.com/oauth2/callback ) > click Create:

  6. It will take some and create the application for you ( Note down the Application ID , you would need it when connecting to dynamics crm using OAuth):

  7. Click on the Settings from the application created and then on Required Permissions:

  8. Now Click on add new:

  9. Then click on Select API:

  10. Select Dynamics CRM Online from Drop Down and click on select:

  11. It will move to the next step “Select Permissions“, select the “Access Dynamics CRM as organization users” option and click on Select again.
  12. Click on Done:
  13. It will take some time and add the required permissions:

    And this is it! the setup is completed , now you can use this app’s Application ID as a Client ID in your application using which you need to connect to dynamics CRM using OAuth such as POSTMAN, SOAP etc.

    I hope this helps!