Reading Data

At a top level, the LinkedIn API divides information into resources for people, companies, groups, and jobs. We also have separate resources that let you search for people, companies, and jobs.

Name Description Resource(s)
People Member profiles, reading or writing network updates, messaging and connections http://api.linkedin.com/v1/people
http://api.linkedin.com/v1/people-search
Groups Reading and writing group posts and comments, group memberships for the authenticated user, joining groups. http://api.linkedin.com/v1/groups
http://api.linkedin.com/v1/posts
Company Company profiles, suggested companies for a user to follow, following companies http://api.linkedin.com/v1/companies
http://api.linkedin.com/v1/company-search
Jobs Jobs posted on LinkedIn http://api.linkedin.com/v1/jobs
http://api.linkedin.com/v1/job-search

Getting your response in XML or JSON

By default, the LinkedIn REST APIs return XML. For a JSON response there are two different methods you can use:

  • The preferred method is setting the "x-li-format" HTTP header to "json".
  • The second method is appending ?format=json to the request URL. This is sometimes easier, but may cause issues with certain types of requests.

Example: Requesting Information about People

Here is the example code that fetches the authenticated user's profile. The ~ is a shortcut for the current user and can be used in any request for the people resource.

Before trying to execute the code below, it's assumed you have an API key/secret and have obtained an OAuth access token.

// Assume you already obtained an access token and imported the appropriate classes
System.out.println("********A basic user profile call********");

String url = "http://api.linkedin.com/v1/people/~";
OAuthRequest request = new OAuthRequest(Verb.GET, url);

// sign the request with my access token
service.signRequest(accessToken, request);

// send the request and get the response
Response response = request.send();

// print out the response body
System.out.println(response.getBody());
<?php
print_line("\n********A basic user profile call********");
$api_url = "http://api.linkedin.com/v1/people/~";
$oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET);
$response = $oauth->getLastResponse(); // just a sample of how you would get the response
print_response($oauth);
# Simple profile call
	print "\n********A basic user profile call********"
	response = make_request(client,"http://api.linkedin.com/v1/people/~")
	print response

Here is an example that gets authenticated user's profile and returns the payload in JSON

url = "http://api.linkedin.com/v1/people/~";
request = new OAuthRequest(Verb.GET, url);

// set a header to tell the server to return JSON
request.addHeader("x-li-format", "json");
service.signRequest(accessToken, request);
response = request.send();
System.out.println(response.getBody());
<?php
print_line("\n********Get the profile in JSON********");
$api_url = "http://api.linkedin.com/v1/people/~";
$oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET, array('x-li-format' => 'json'));
print_response($oauth);
# Simple profile call, returned in JSON
	print "\n********Get the profile in JSON********"
	response = make_request(client,"http://api.linkedin.com/v1/people/~",{"x-li-format":'json'})
	print response

Here is an example that gets the current user's connections

System.out.println("********Get my connections - going into a resource********");
url = "http://api.linkedin.com/v1/people/~/connections";
request = new OAuthRequest(Verb.GET, url);
service.signRequest(accessToken, request);
response = request.send();
System.out.println(response.getBody());
<?php
print_line("\n********A basic user connections call********");
$api_url = "http://api.linkedin.com/v1/people/~/connections";
$oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET);
print_response($oauth);
# Simple connections call
	print "\n********Get the connections********"
	response = make_request(client,"http://api.linkedin.com/v1/people/~/connections")
	print response

Here is an example that gets the first 10 of the user's connections

url = "http://api.linkedin.com/v1/people/~/connections?count=10";
request = new OAuthRequest(Verb.GET, url);
service.signRequest(accessToken, request);
response = request.send();
System.out.println(response.getBody());
<?php
// This call extends on the above by limiting the number of results to 10
print_line("\n********Get only 10 connections - using parameters********");
$api_url = "http://api.linkedin.com/v1/people/~/connections";
$oauth->fetch($api_url, array("count" => 10), OAUTH_HTTP_METHOD_GET);
print_response($oauth);
# Simple connections call
	print "\n********Get only 10 connections - using parameters********"
	response = make_request(client,"http://api.linkedin.com/v1/people/~/connections?count=10")
	print response