LinkedIn API Setup Guide 2020

The LinkedIn Marketing API is used to programmatically query data, create and manage ads, create and manage campaigns, get account-related data, and perform a wide variety of other tasks. This guide helps you complete all the steps needed to use marketing API successfully.

The LinkedIn API is the REST API is the heart of all programmatic interactions with LinkedIn. LinkedIn API enables you to bring the power of the world’s largest professional network to your apps. By using the LinkedIn API you can use several LinkedIn services.

 Steps to be followed, to use LinkedIn API (Linkedin Marketing API) successfully:- 

1.First create an app under LinkedIn Developer

Go to Linkedin Developer , You should see the image below as your screen. 

Fill up the detail above and click on “create APP”

In order to finish App creation you need to verify your App. Click on “Verify”

You should see a pop-up asking for Verifying company, scroll down and click on “Generator URL”.

If you have the Admin the Linkedin Page or have Admin access to the LinkedIn page for which you are building this app. Copy this verifying link and open it in the new tab and click on “verify” or else send this link to admin the page and ask them to verify it.

Finally come back to the Verify company pop-up and click on “I’m done”.

Continue to LinkedIn Developers. Select the app you just created.

2. Accessing Marketing API

In order to proceed ahead, you are going to need access to the Marketing Developer Platform (MDP).

a. Getting MDP for your APP:

From the previous step you must be on the below screen.

click on the “Products” tab. Look for the Marketing Developer Platform(MDP) and click on the “select” button.

An email will be sent to the primary email address of your member profile with a link to complete a form. You need to fill out the “Marketing Developer Platform Access Request Form”.

Note: After submitting form wait for some time ( around 1 day ).

b. Add ads account to MDP (Optional):

Under your app go to “product” tab and you will see the “view setting” option at the side of Marketing Developer Platform

To add ads accounts click on “view setting” and enter ad account number {which you will find under Linkedin Campaign Manager. Just below the account you want to add to MDP note down the (account id).} lastly click on “save ad Account”.

3. Generating Access Token

Step1: Go to the LinkedIn Developer Portal, select your app, navigate to the “Auth” section and allocate your “Client ID” and “Client Secret”. Note them down since you are going to need them moving forward in process.

Step2: From the same “Auth” tab, scroll to the bottom. Under “OAuth 2.0 Settings”, add the Postman callback URL https://www.getpostman.com/oauth2/callback.

Step3: Open a new tab in Postman and navigate to “Authorization”.

Step 4: Change the “TYPE” to “Oauth 2.0”.

Step 5: Click “Get New Access Token”.

Step 6: Fill out the form in the pop up window with the following values and click “Request Token”.

  • Grant Type = Authorization Code
  • Callback URL = https://www.getpostman.com/oauth2/callback
  • Auth URL = https://www.linkedin.com/oauth/v2/authorization
  • Access Token URL = https://www.linkedin.com/oauth/v2/accessToken
  • Client ID = {Copy this from the “Auth” tab in the developer portal}
  • Client Secret = {Copy this from the “Auth” tab in the developer portal}
  • Scope = contacts,r_organization_social,w_organization_social,rw_organization_admin,rw_ads,r_ads_reporting,r_liteprofile or contacts or r_ads,rw_ads,r_ads_reporting,r_basicprofile,rw_organization_admin
  • Client Authentication = Send client credentials in body
  • State = any unique string eg: 12abc34.

Postman will take you to the LinkedIn authorization page. You may be prompted to log into LinkedIn before getting to the below screen. Click “Allow” to authorize the request.

After that Postman will then display your access token and refresh_token. 

If you were able to pass all the hurdles till now, Congratulations!..

If not, don’t worry, take a break and try again. I’m confident you will crack it. 

4. Test the Access Token (i.e making first API call).

Store the credentials (Access Token, Refresh Token, Expiry Time, etc) in JSON format by creating a separate JSON file. This will help you manage your LinkedIn credential easily and keep it more secure.

{
    "linkedin_cred":
    {
        "access_token":"Replace it with LinkedIn access_token",
        "client_id":"Replace it with client id",
        "Client_secret":"Replace it with client secret",
        "Account_id":"Replace it with LinkedIn ads account id",
        "expires_in":"Replace it with access_token expiry",
        "refresh_token":"Replace it with refresh_token",
        "refresh_expire":"Replace it with refresh_token expiry"
    }
}

Understand the below code and create a test code. I named the python code file below as “access_token_check”.

#!/usr/bin/python3
import requests
import json
 
#reading client_id json file
cred_file = "./linkedin_cred.json"
cred = open(cred_file, 'r')
ln_cred= json.load(cred)
 
access_token = ln_cred["linkedin_cred"]["access_token"]
 
url = "https://api.linkedin.com/v2/me"
 
headers = {"Authorization": "Bearer "+access_token}
#make the http call
r = requests.get(url = url, headers = headers)
 
if r.status_code != 200:
    print("something went wrong :",r)
else:
    response_dict = json.loads(r.text)
    print("Account Description :\n",response_dict)

By running the above file with (python3 ./access token check.py). You should see your Linkedin Profile data printed in the console.

If you see the above output that means the access_token you generated through the above process is working and you are good to go with your advanced application using LinkedIn API.

Congratulation! you have successfully set up LinkedIn API. Now, here’s my guide to help you in developing a complete Python code for extracting campaign data using LinkedIn API with full code structuring. End-To-End LinkedIn Campaign Data Extraction Programmatic Solution.

For any suggestions or doubts ~ Get In Touch

Leave a Reply

Your email address will not be published. Required fields are marked *