Dynamics 365 and LinkedIn Power Automate integration

Posted by     "Andrey Paltusov" on Monday, November 15, 2021

Оглавление

Intro

   There are several LinkedIn tools in Dynamics 365 - LinkedIn Sales Navigator for Dynamics 365 and LinkedIn Lead Gen integration, but these are rather marketing tools that also require additional costs. What if you just need to enrich your contacts with Linked Profile data? Linked has its own API and it would be nice to use it. In the same time, Power Platform has an integration mechanism and it would be good to use it too. First of all, let’s understand the mechanism for getting data from the API. They are described very well in this video. The data exchange scenario will be as follows:

  1. The employee inputs a LinkedIn profile link into the D365 contact form
  2. Letter is sent to the contact with a request to access his profile information.
  3. The contact opens the link and approves the request.
  4. Power Automate(PA) receives redirect Url with authorization code and gets Bearer token.
  5. PA retrieves LinkedIn Url from Dataverse contact entity and makes request to the LinkedIn by VanityName
  6. PA updates data in Dataverse

LinkedIn application registration

   The first thing you need to do is to register the application in LinkedIn and add it the necessary products. Unfortunately, LinkedIn refused to give me permission for retrieving by VanityName. Details of how to register the application and obtain rights are in this video.

On this step you can leave authorized redirect Url field empty for now.

Power Apps confirmation receiver

   Now we need to create a listener to which requests for linked access will be redirected. In our case the receiver will be the Power Automate http receiver.

Copy Url to the LinkedIn “Authorized redirect URLs for your app” field.

Dynamics 365

   Now you can create new field on the contact form and configure confirmation message. This message we will send to the contact, to request access to his profile.

In the mail message, we will have a link with access request to the profile. There you need to add the address of the redirect link in the redirect_uri parameter, encoded at https://www.urlencoder.org/, and add the contact GUID to the state parameter in order to understand from whom exactly the confirmation came, and which contact we will update. I got the GUID using this tool https://github.com/demianrasko/Dynamics-365-Workflow-Tools

Authentication and LinkedIn request

   Initialization of the variable to store Vanity Name.

The next step is LinkedIn authentication.

Code = triggerOutputs()['queries']['code']

Check that the authorization was successful and get the authorization token

{
    "type": "object",
    "properties": {
        "access_token": {
            "type": "string"
        },
        "expires_in": {
            "type": "integer"
        }
    }
}

Get contact by Id and link from there, check if it is not empty.

State = triggerOutputs()['queries']['state'] – this is the contact GUID that we sent in the message 
length('varVanityName')

If the value of the field with the link is not empty, then we get VanityName from the Url and execute the request to get data from LinkedIn.

split(variables('varVanityName'),'/')[4]

Unfortunately, I could not get the rights for my test application for extended methods like searching by Vanity Name, but process works with test request of my profile data. Hope this guide will help to complete data exchange with complete scenario.

--Андрей Палтусов--


comments powered by Disqus