Mon, 10/26/2020 - 09:40 By Mattias Liloia

Description

Recently, I had the requirement of displaying data from Dynamics 365 in a PHP website. In PHP there is a command named "CURL", which lets you execute remote requests of all kinds. In general, CURL is a command line utility to transfer data and it supports many protocols. Its widely known and chances are very high, it will be available in your command line tool of choice. More information about CURL can be found here: https://curl.haxx.se/

There are two steps involved to establish a connection between your client and Dynamics 365.

  1. Authentication:
    Create an application user following these steps: https://docs.microsoft.com/en-us/power-platform/admin/create-users-assign-online-security-roles#create-an-application-user

    Assign the application user appropriate permissions in Dynamics 365 by defining a custom security role.

    Execute the first CURL request to acquire a new bearer token:
    curl -X POST https://login.microsoftonline.com/{tenant}/oauth2/token -F grant_type=client_credentials -F resource={resource} -F client_id={client_id} -F client_secret={client_secret}

    {tenant}: GUID or friendly name of your directory tenant.
    {resource}: Resource which you want to access. This is your Dynamics 365 instance URL (e.g. https://testcompany.crm4.dynamics.com).
    {client_id}: App registration client id.
    {client_secret}: App registration client secret.

    curl 1
     
  2. Retrieve data from Dynamics 365:
    Execute the second CURL request including the token retrieved from the first request:
    curl --location --request GET "https://{resource}/api/data/v9.1/accounts?$select=name" --header "Authorization: Bearer {token}" 

    {resource}: This is your Dynamics 365 instance URL (e.g. https://testcompany.crm4.dynamics.com).
    {token}: Token retrieved from the first request.

    curl 2

 Conclusion

CURL is a very powerful tool and could be a potential option while integrating rather exotic systems. Apart from that, it's running on almost every system and will help you, if you don't have Postman at your fingertips.

We can also consult some other articles of our blog on the same topic : 

 

Add new comment

Image CAPTCHA
Enter the characters shown in the image.