Understanding Field Selectors

We return a default set of fields for each resource you request. However, you can override this using field selectors to explicitly request the data you want. Do this when the default fields may not meet your application's specific needs. For a detailed explanation of field selectors, read the reference documentation.

Since each resource has nested resources and our domain model is hierarchical, you can include sub-fields and define their returned values to any depth you need. This table demonstrates how this works in practice.

URL Description
https://api.linkedin.com/v1/companies/1337 Access default information for the company with id=1337 (LinkedIn)
https://api.linkedin.com/v1/companies/1337:(id,website-url) Get just the id and website for the company
https://api.linkedin.com/v1/companies/1337:(id,website-url,locations) This request returns the id and website url along with a collection of all the locations for a company - locations are a separate type of resource with a default field set
https://api.linkedin.com/v1/companies/1337:(id,website-url,locations:(description,is-headquarters)) This request specifies which fields to return for each location: description, postal-code, and whether or not this location is the headquarters
https://api.linkedin.com/v1/companies/1337:(id,website-url,locations:(description,is-headquarters,address:(street1,city,state,postal-code,country-code))) This request demonstrates adding another level of expansion - address is a resource with a default field set, and you can define exactly which fields you want there.

Example: Using Field Selectors

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

Getting a basic user profile with only 3 fields returned

url = "https://api.linkedin.com/v1/people/~:(first-name,last-name,positions)";
request = new OAuthRequest(Verb.GET, url);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println(response.getBody());
<?php

print_line("\n********A basic user profile call with field selectors********");
$api_url = "https://api.linkedin.com/v1/people/~:(first-name,last-name,positions)";
$oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET);
print_response($oauth);
print "\n********A basic user profile call with field selectors********"
	api_url = "https://api.linkedin.com/v1/people/~:(first-name,last-name,positions)"
	response = make_request(client,api_url)
	print response

Get the user and then get all the user's positions, returning only the company name for the positions

url = "https://api.linkedin.com/v1/people/~:(first-name,last-name,positions:(company:(name)))";
request = new OAuthRequest(Verb.GET, url);
service.signRequest(accessToken, request);
response = request.send();
System.out.println(response.getHeaders().toString());
System.out.println(response.getBody());
<?php

print_line("\n********A basic user profile call with field selectors going into a subresource********");
$api_url = "https://api.linkedin.com/v1/people/~:(first-name,last-name,positions:(company:(name)))";
$oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET);
print_response($oauth);
print "\n********A basic user profile call with field selectors going into a subresource********"
	api_url = "https://api.linkedin.com/v1/people/~:(first-name,last-name,positions:(company:(name)))"
	response = make_request(client,api_url)
	print response

A more complicated example selecting top level and sub-fields from posts in groups

url = "https://api.linkedin.com/v1/groups/3297124/posts:(id,category,creator:(id,first-name,last-name),title,summary,creation-timestamp,site-group-post-url,comments,likes)";
request = new OAuthRequest(Verb.GET, url);
service.signRequest(accessToken, request);
Response response = request.send();        
System.out.println(response.getBody());
<?php

print_line("\n********A more complicated example using postings into groups********");
$api_url = "https://api.linkedin.com/v1/groups/3297124/posts:(id,category,creator:(id,first-name,last-name),title,summary,creation-timestamp,site-group-post-url,comments,likes)";
$oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET);
print_response($oauth);
print "\n********A more complicated example using postings into groups********"
	api_url = "https://api.linkedin.com/v1/groups/3297124/posts:(id,category,creator:(id,first-name,last-name),title,summary,creation-timestamp,site-group-post-url,comments,likes)"
	response = make_request(client,api_url)
	print response