This article will discuss about how to use LinkedIn API with step-by-step integration guide and full documentation list. Let’s get started!
Overview of LinkedIn API
LinkedIn, as we all know, is the most popular professional channel for connecting people from various services and sectors. And if you want to access data from LinkedIn, then you need to leverage LinkedIn API. Accessing data and information from LinkedIn is many a time needed for business purposes or for developing advanced applications, and hence LinkedIn public API is useful.
LinkedIn developer API and key functionalities
In this section, we will discuss LinkedIn developer API and its key functionalities. It will help you to answer your query on Does LinkedIn have an API?
- LinkedIn Open API has a protocol that defines the 14 resource methods. Each of the resource methods has its interfaces which are standardized and with the required semantics
- In LinkedIn API integration, there is a Rest.li protocol which is for supporting query parameters and resource keys
- In addition to your query on Does LinkedIn have an open API, yes it does and one of the key concepts is the LinkedIn API client libraries which are kept to construct API requests easily.
Also read: How to use the Zoom API; a step-by-step integration guide and documentation list
How to use LinkedIn API – step-by-step integration guide
In this section, we will check the detailed steps on how to use LinkedIn API.
- For LinkedIn API access, OAuth 2.0 is used for user authorization and user authentication
- There are two types of LinkedIn rest API authorization flows – Member Authorization which is a 3-legged OAuth and Application Authorization which is a 2-legged OAuth
- The first important concept of LinkedIn data API integration is to establish the input and output data formats using the following code : Content-Type: application/json and in JSON format
- The next important step is to generate a LinkedIn API key or token with Postman. You need to visit the LinkedIn developer portal and click the “Auth” tab to find out the client id and client secret key.
- Next under the OAuth 2.0 settings, you need to add the callback URLs – https://oauth.pstmn.io/v1/callback and https://oauth.pstmn.io/v1/browser-callback
- Then fork the collections and fork the environments under each collection
- The environment variables Client id and the Client secret are then entered
- Each collection title must be opened to check its Authorization tab. Click on the “Get new access token” button to authenticate the LinkedIn API connections, and select the grant type and the callback URL. Then specify the Authorization URL and access token URL. Use the environment variables as filled in. Define the scope as per the sample : {rw_ads,r_basicprofile,w_organization_social,w_member_social,rw_organization_admin}
- When the grant type is Authorization Code, the client authentication code is Send client credentials in body and when the grant type is Client credentials, the client authentication code is Send as Basic Auth header
- The Authorization or authentication needs to be identified in the next step and allowed or permitted
- In the next step, the developer LinkedIn API key or access token will be displayed and you must select the “Use token” button to set it up
- Input and output data formats are a must to be set in JSON format, using the following HTTP content type Content-Type: application/json
- The field projection controls need to be set up to determine the display of an entity’s data while responding to an API request. Some fields within the projections may not be required and can be eliminated. The projections are defined using &fields= as the query parameter and then mentioning the names of the fields expected to be returned by separating via commas.
- API calls need to be made by breaking them up into multiple page results. And this is required when there are a large number of entities to be returned via the API calls. Start and count are the query parameters that help paginate through the API calls’ results. The query is to mention the “start” value as 0 and the “count” value as N. For the next page, the “start” value is mentioned as N, keeping the count value the same, and it goes on. The details of the codes are mentioned in here. A sample request:
GET https://api.linkedin.com/v2/{service}
- Query tunneling is essential for LinkedIn rest API assessment. It is used for resolving requests – some requests are with Body and some without Body.
- For requests without Body, the steps are:
-
-
- The request needs to be changed from GET to POST.
- Add the X-HTTP-Method-Override header, using the original HTTP method (-H “X-HTTP-Method-Override: GET”).
- Add the Content-Type header (-H “Content-Type: application/x-www-form-urlencoded”).
- Move the query string to the body of the request
- Sample code: Copy
-
curl -X GET ‘https://api.linkedin.com/v2/organizationalEntityAcls?q=roleAssignee&projection=(elements*(organizationalTarget~))’ \
-H ‘Authorization: Bearer redacted’
- For requests with Body, the steps are:
- The request type needs to be changed from PUT to POST if the original request type was PUT. If the original request type was POST, keep it as POST.
- Add the X-HTTP-Method-Override header using the original HTTP method -H ‘X-HTTP-Method-Override: POST’ for POSTs or -H ‘X-HTTP-Method-Override: PUT’ for PUTs.
- Add the Content-Type header -H ‘Content-Type: multipart/mixed; boundary=xyz’.
- Sample code: curl -X POST ‘https://api.linkedin.com/v2/adCreativesV2?ids=List(47770196)’ \
-H ‘Authorization: Bearer redacted’ \
-H ‘Content-Type: application/json’ \
-H ‘X-Restli-Protocol-Version: 2.0.0’ \
-H ‘X-RestLi-Method: BATCH_PARTIAL_UPDATE’ \
–data ‘{“entities”: {“47770196”: {“patch”: {“$set”: {“status”: “ACTIVE”}}}}}’
- Query tunneling is essential for LinkedIn rest API assessment. It is used for resolving requests – some requests are with Body and some without Body.
- LinkedIn API requests are governed by rate limits to limit the maximum number of calls in 24 hours. There are two kinds of LinkedIn API limits – Application and Member.
- Application LinkedIn API rate limit – used to set the total number of calls made by an application daily
- Member LinkedIn API rate limit – used to set the total number of calls made by a member for each application daily
- Several request methods can be used as part of LinkedIn API integration. Some examples are
- LinkedIn search API can be used to search keywords, companies, locations, industries, and so on.
LinkedIn API documentation references
Let us now find out the LinkedIn API documentation references.
- For getting access to LinkedIn API, here is the link.
- For authentication overview, the link for the LinkedIn API tutorial is here.
- To generate the LinkedIn API access token, the LinkedIn developer API documentation link is here.
- To find out details on the developer portal tools, check out the link.
- The link for the LinkedIn API docs on API concepts, data formats, field projections, paginations, request methods, etc. is here.
- If you want to check the LinkedIn API clients then the LinkedIn Rest API documentation link is here.
- The link for sample applications can be checked in the link here.
- The best practices for integrating LinkedIn API can be checked in the link.
Also read: How To Use Notion API a step-by-step Integration Guide and Full Documentation List
LinkedIn API examples
In this section, we will check the LinkedIn API examples or sample codes using various types of APIs like Python, PHP, JavaScript, etc.
How to use LinkedIn API Python
There are two ways to use LinkedIn API Python to fetch profile data. One is getting permission from the profile using LinkedIn Python API to extract data into your application which is free and available. The second way is fetching profile data with access to approved developers using a paid subscription, an answer to your question on how to use LinkedIn API in Python.
Use the sample code of Python LinkedIn API to receive the data profile, here is the link
LI_AUTH_URL = ‘https://www.linkedin.com/oauth/v2/authorization’
url = requests.Request(‘GET’, LI_AUTH_URL,
params={
‘response_type’: ‘code’,
‘client_id’: LINKEDIN_CLIENT_ID,
‘redirect_uri’: LINKEDIN_REDIRECT_URI,
‘state’: secrets.token_hex(8).upper(),
‘scope’: ‘%20’.join([‘r_liteprofile’, ‘r_emailaddress’, ‘w_member_social’]),
}).prepare().url
return url
How to use LinkedIn API NPM
As a first step in using LinkedIn API NPM, you need to understand that there are 3 types of methods.
- Single entity
- Multiple entities
- Mutations
Then comes scrollers as part of LinkedIn API node JS or NPM for easy navigation of pages, the sample code is below.
// index scroller
let companiesScroller = client.search.searchCompanies();
let companies = await companiesScroller.scrollNext(); // returns first page with 10 results
companies = await companiesScroller.scrollNext(); // next page
companies = await companiesScroller.scrollBack(); // previous page
// overriding skip and limit
companiesScroller = client.search.searchCompanies({ skip: 100, limit: 1 });
companies = await companiesScroller.scrollNext(); // returns first page with 1 results
companies = await companiesScroller.scrollNext(); // next page
companies = await companiesScroller.scrollBack(); // previous page
// overriding createdBefore for time scroller
const twoDaysAgo = moment().subtract(2, ‘days’).toDate();
let messagesScroller = client.message.getMessages({
conversationId: CONVERSATION_ID,
createdBefore: twoDaysAgo
});
messages = await companiesScroller.scrollNext();
How to use PHP LinkedIn API
Here are some examples of how to use PHP LinkedIn API
You can use the method setAccessToken()for setting the token and the LinkedIn share API PHP example is
$client->setAccessToken($accessToken);
PHP LinkedIn API example for API calls:
$profile = $client->api(
‘ENDPOINT’,
[‘parameter name’ => ‘its value here’],
‘HTTP method like GET for example’
);
PHP LinkedIn API tutorial contains sample codes for setting LinekdIn API request headers as below:
$client->setApiHeaders([
‘Content-Type’ => ‘application/json’,
‘x-li-format’ => ‘json’,
‘X-Restli-Protocol-Version’ => ‘2.0.0’, // use protocol v2
‘x-li-src’ => ‘msdk’ // set a src header to “msdk” to mimic a mobile SDK
]);
How to use LinkedIn API Angular
To use LinkedIn API Angular, the installation code is $ npm install angular-linkedin-sdk
As specified in the URL
Now coming to the LinkedIn API AngularJS tutorial, a sample code for usage us
import { BrowserModule } from ‘@angular/platform-browser’;
import { NgModule } from ‘@angular/core’;
import { AppComponent } from ‘./app.component’;
// Import the library
import { LinkedInSdkModule } from ‘angular-linkedin-sdk’;
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
// Specify your library as an import
LinkedInSdkModule
],
providers: [
// Inject apiKey and, optionally, authorize to integrate with LinkedIN official API
{ provide: ‘apiKey’, useValue: ‘YOUR_API_KEY’ },
{ provide: ‘authorize’, useValue: ‘true/false’ }, // OPTIONAL by default: false
{ provide: ‘isServer’, useValue: ‘true/false’ } // OPTIONAL by default: false
],
bootstrap: [AppComponent]
})
export class AppModule { }
How to use LinkedIn iOS API
As a first step to using LinkedIn iOS API, it is essential to create two keys – Client ID and Client Secret. Next is to access the LinkedIn API token using OAuth. An authorized request needs to be made using the LinkedIn API access token to get the profile URL. A button is displayed, and clicking on it opens the profile in Safari.
On the website, need to access the My Applications area and find out the Create Application button. All the data needs to be filled up as soon as the form appears for creating the application.
How to use LinkedIn API Javascript
Here are some examples of how to use LinkedIn API javascript
A sample code using LinkedIn login API javascript for a simple API request
const { RestliClient } = require(‘linkedin-api-client’);
const restliClient = new RestliClient();
restliClient.get({
resourcePath: ‘/me’,
accessToken: <THREE_LEGGED_ACCESS_TOKEN>
}).then(response => {
const profile = response.data;
});
A sample code using rest API linkedin in javascript for a finder API request
const { RestliClient } = require(‘linkedin-api-client’);
const restliClient = new RestliClient();
restliClient.finder({
resourcePath: ‘/adAccounts’,
finderName: ‘search’,
queryParams: {
search: {
status: {
values: [‘ACTIVE’, ‘DRAFT’]
},
reference: {
values: [‘urn:li:organization:123’]
},
test: true
}
},
versionString: ‘202212’,
accessToken: <THREE_LEGGED_ACCESS_TOKEN>
}).then(response => {
const adAccounts = response.data.elements;
const total = response.data.paging.total;
});
Link is here.
How to use LinkedIn API integration with Laravel
Let’s now try to check some sample examples of how to use LinkedIn API integration with Laravel. The sample code for communicating with LinkedIn API using json is as follows:
$body = array(
‘comment’ => ‘Testing the linkedin API!’,
‘visibility’ => array(‘code’ => ‘anyone’)
);
LinkedIn::post(‘v1/people/~/shares’, array(‘json’=>$body));
LinkedIn::post(‘v1/people/~/shares’, array(‘body’=>json_encode($body)));
To understand the response data type, here is the sample code.
// By setter
LinkedIn::setResponseDataType(‘simple_xml’);
// Set format for just one request
LinkedIn::get(‘v1/people/~:(firstName,lastName)’, array(‘response_data_type’=>’psr7’));
How to use LinkedIn Java API example
LinkedIn Java API example as mentioned in the link is as below, used for accessing the token
VersionedLinkedInClient client = new DefaultVersionedLinkedInClient(Version.DEFAULT_VERSION);
LinkedInClient.AccessToken accessToken = client.obtainUserAccessToken(clientId, clientSecret, redirectURI, code);
The sample code for creating LinkedIn share is as below:
VersionedPostConnection postConnection =
new VersionedPostConnection(new DefaultLinkedInClient(authToken));
Distribution distribution = new Distribution(Distribution.FeedDistribution.MAIN_FEED);
String commentary = “Message here”
Post post = new Post(ownerURN, commentary, distribution, Post.LifecycleState.PUBLISHED,
Post.Visibility.PUBLIC);
String articleLink = “https://www.example.com/1234”;
String title = “title”;
String description = “description”;
PostUtils.fillArticleContent(post, articleLink, imageURN, title, description);
URN postURN = postConnection.createPost(post);
LinkedIn API pricing
Now comes the question is LinkedIn API free? The basic plan is free but there are different LinkedIn API pricing plans. The standard LinkedIn API code is USD 59 per month and allows access to 500 profiles. The LinkedIn API cost for the premium plan is USD 499 per month and allows access to 10,000 profiles.
Also read: How to use Slack API; a step-by-step integration guide and full documentation list
Most used LinkedIn APIs
In this last section, we will discuss in brief the most used LinkedIn APIs and their respective links.
LinkedIn Ads API
The LinkedIn Ads API helps to access AD forms, AD campaigns, and AD analytics, here is the link. LinkedIn jobs API
LinkedIn Jobs API is used for authorizing third parties to post jobs on behalf of customers, link is here.
LinkedIn Sales Navigator API
The LinkedIn sales navigator API is used to establish the connection between the LinkedIn members and external vendor ids, please refer to the link.
LinkedIn Profile API
The LinkedIn profile API is used to return the profile of a LinkedIn member and other details as per the privacy settings, here is the link.
LinkedIn Learning API
LinkedIn learning API is used for accessing the learning content and technical training guides, which can be checked from the link.
LinkedIn Messaging API
LinkedIn messaging API or communication API help in sending invitations and messages to existing connections, the link is here.
LinkedIn Recruiter API
The LinkedIn recruiter API posts and manages basic and advanced jobs on the website.
LinkedIn Post API
LinkedIn post API is used to create and retrieve both organic and sponsored posts, the link is here.
LinkedIn Inmail API
LinkedIn Inmail API is used to send emails to the connections via the website.
LinkedIn OAuth API
LinkedIn OAuth API is used for user and API authentication, the link for details.
LinkedIn Groups API
Using LinkedIn groups API, you can connect to millions of groups within the website, the details are available in the link.
LinkedIn API Test Console
The LinkedIn API test console is used to capture test results, logs, and debugging, to check to Visit the link.
LinkedIn API Company Search
LinkedIn API company search is used to find companies using the keywords, location, industrial sector, and other criteria. Details to be checked in here.
LinkedIn Ad Analytics API
Using LinkedIn Ad Analytics API, one can check the insights and performance of campaigns on LinkedIn. Check the link for details.
LinkedIn Conversion API
LinkedIn conversion API is used to check how many prospect customers earned through ads and campaigns. Check details in the link.
Kuntala is a versatile writer with a focus on diverse areas around work, productivity, collaboration at work, hiring, management, HR, and training. Her background of past experience in technology and consulting helps in molding razor-sharp insights into the research and user-focused content she creates. Professionally she is an IT consultant in a sales role and also a writer of short stories and poems, travel blogger, and fashion influencer.