Publish CMP content from Sitecore Content Hub to LinkedIn


In this blog, I would like to show you the steps to publish a CMP (Content Marketing Platform) content with an associated asset from Sitecore Content Hub (4.x) to LinkedIn social media platform.

Step 1: Create an LinkedIn OAuth2 access token

Follow the instructions found in this page https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin%2Fcontext&tabs=HTTPS to create an OAuth2 token.

For this example, I've selected "r_liteprofile%20r_emailaddress%20w_member_social" as the scope for my application created in the LinkedIn Developer Portal. Actually, you cannot select the scope directly but rather through the Products available for selection - "Shared on LinkedIn, Sign in with LinkedIn" as shown in the screenshot below.


Make a note or copy this OAuth token in a secure place as you would need it in the subsequent steps below. If you lose it, you'd have to go through the steps again to generate another one.

Tip: For quick and hassle free setup, I've used Postman.

Step 1a: Make an Postman API call to https://api.linkedin.com/v2/me with the OAuth token generated above in Postman or any other tool and copy the "id" value returned in the JSON result.


Step 2: Setup Azure Service Bus, storage account

Setup an Azure Service Bus and create a topic inside with the following details:

Topic Name: linkedin

Subscription Name: sch

Create an Azure Storage account for the Azure Function described in Step 4 below.

Step 3: Setup Sitecore Content Hub

Setup a Sitecore Content Hub sandbox with version 4 and above (preferably in the latest version 4.1) with CMP, DAM selected as features.

  • Setup an Azure Service Bus action that points to the Service Bus connection string created above
  • Setup an trigger with "Entity modification" objective and "In background" execution type with the following conditions as in the screenshot
  • Setup OAuth token in Content Hub and copy the ClientId and ClientSecret in a secured place
  • Setup an API user with Superuser privileges, note down the password

Step 4: Setup Azure Function as an integration layer between Content Hub and LinkedIn

Download the source code from GitHub and open the solution in Visual Studio

For local development and testing, create a local.settings.json file with the following data
 {
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "azure storage account connection storage string",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "ServiceBusConnection": "azure service bus connection string>"
  }
}  



Compile the source code and deploy the Azure function to cloud.

Setup the following App settings in your Azure Function with the following keys:
  1. MHost - Appropriate value of your Content Hub instance (ex: https://xxxx.stylelabs.io)
  2. MClientId - Content Hub OAuth Client Id setup in Step 3 above
  3. MClientSecret - Content Hub OAuth Client Secret
  4. MUsername - Content Hub API username
  5. MPassword - Content Hub API user password
  6. LinkedInPersonId - Person Id value from Step 1 above
  7. LinkedInOAuthToken - OAuth token value from Step 1 above
Setup the following connection strings:
  1. ServiceBusConnection - Copy the Azure Service Bus connection string
  2. AzureWebJobsStorage - Copy the Azure Storage account connection string
Now the connector is ready to publish CMP content to LinkedIn as a share post.

Step 5: Create a CMP content and publish it

In Sitecore Content Hub, navigate to CMP search page and create a CMP content, associate an asset and push through the workflow until it reaches "Ready to Publish" state.

At this stage, the connector (Azure Function) picks up the message from Azure Service Bus, makes an API call to Content Hub, reads the CMP content and downloads the asset and creates an LinkedIn share post.

Please note that the connector also works for textual CMP content without asset as well.

Step 6: Login to LinkedIn and view the share post

Login to LinkedIn and go to the share feed. You should see the post created by the connector.

I hope you like the blog post. Please leave any comments, suggestions or feedback if you find this useful.





Comments