LinkedIn API Setup Guide – LinkedIn Developer Account Setup

LinkedIn API – How to get an OAuth access token and how to call the API – Step-by-step guide

Hi Everyone, hope you are keeping well. Thank you so much for stopping by. Today we are going to set up a LinkedIn developer account to use LinkedIn API, create an app in the developer account, enable LinkedIn Marketing API, and eventually make our first LinkedIn API call using python. In short, we will see how to set up LinkedIn API.

What is Linkedin API?

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 LinkedIn Marketing API successfully.

The LinkedIn API is the REST API and 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 (also known as LinkedIn Marketing API) you can use several LinkedIn services. Most importantly you can extract your campaign performance data using this API.

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

Table of Content:

1. First create an app under LinkedIn Developer

In order to set up a LinkedIn developer account. Go to LinkedIn Developer, You should see the image below on 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”.

NOTE for this step you need to have admin access to the LinkedIn Page or need to send the link to the Admin of the page. Copy this verifying link and open it in the new tab and click on “verify” or else send this link to the admin of 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. Enable 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 the form wait for some time (i.e around 1 day).

B. Add ads account to MDP (Optional)

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

To add ad accounts click on “view setting” and enter the 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). Don’t forget to 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 the 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 in to 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 the 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 -> “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.

Hope I was able to solve the problem. If you like this article and think it was easy to understand do share it with your friends and connection. Thank you! see you soon.

For any suggestions or doubts ~ Get In Touch

Checkout out my other API Integration and Coding Solution Guide