Search API Connector Documentation
Import LinkedIn Ads Data to Google Sheets
In this guide, we will pull data from the LinkedIn API directly into Google Sheets, using the API Connector add-on for Sheets.
The LinkedIn API limits data for privacy reasons; don't expect a way to pull out profile information for anyone but yourself. However, this API is perfect for pulling out advertising performance data from the LinkedIn Ads Reporting API.
- Before You Begin
- Part 1: Connect to the LinkedIn Ads API
- Part 2: Pull Data from LinkedIn Ads to Sheets
- Part 3: Create a Custom API Request
- Part 4: Handle Pagination
- Part 5: Notes
- Part 6: API Documentation
Before You Begin
Click here to install the API Connector add-on from the Google Marketplace.
Part 1: Connect to the LinkedIn Ads API
The easiest way to get started with the LinkedIn Ads API is through API Connector’s built-in integration.
- Select LinkedIn Ads from the drop-down list of applications
- Under Authorization, click Connect to LinkedIn
- You will be directed to LinkedIn and asked to authorize the connection. Click Allow.
- You'll now be returned to your Google Sheet, and can verify that your LinkedIn API connection is active.
Part 2: Pull Data from LinkedIn Ads to Sheets
Now that we’re connected, let’s pull some data into Sheets.
- In the Endpoint section, choose
/adAnalytics?q=analyticsto get reporting data in your sheet.
- In the Request parameters section, select one or more of your accounts from the dropdown menu.
- Fill in the other required parameters:
dateRange, select fixed dates from the calendar input or use dynamic values from the cells in your sheet.
- Optionally enter the text
projectionfield. This will retrieve some additional useful fields like campaign names (without using projection, you'll get just the IDs).
- Click Edit fields to select just the fields you want and assign them to specific columns in your report.
- Run your request.
Part 3: Create a Custom API Request
Alternatively, you can create a custom request instead of using API Connector’s built-in integration, using any of the API URLs shown in the API documentation.
Example 1: Fetch metrics with Statistics Finder
Here's a complete example using LinkedIn's X-Restli protocol and their new versioned API. The LinkedIn Statistics Finder method allows you to include up to three "pivots" (i.e. dimensions). Substitute in your own account ID where it says
your_account_id, and your own dates into the
- Request URL:
Note the values returned in the
elements.pivotValues fields as these are the URNs (IDs) that we'll look up next.
Example 2: Fetch campaign names with URN Resolution
LinkedIn's API is rather inconveniently designed as it generally returns URNs (IDs) instead of names. The request above will return URNs for the three pivots listed (CREATIVE, CAMPAIGN, and ACCOUNT). To convert these URNs into meaningful names, we need to make a separate requests, using the LinkedIn URN resolution lookup table to determine the correct endpoint.
For this example, we'll look at the elements.pivotValues field reading
urn:li:sponsoredCampaign:xxxxxxxx . From the URN resolution lookup table, we can see that the
sponsoredCampaign string means we call the
Plug your account ID and campaign ID into the request URL below.
- Request URL:
As you can see, that returned the campaign name.
Example 3: Fetch ad creative names with the content reference field
OK, now it gets a bit complicated 😀
Ad creatives are returned with an URN that looks like this
Just as with
sponsoredCampaign, you can use the URN resolution table to find the correct endpoint for
sponsoredCreative expansion, which is
/creatives. Run a request like this to the
However, unlike the
/adCampaigns endpoints, running a request to the
/creatives endpoint does not directly return the ad name. Instead, check the value returned in the
content.reference field, and make a second call to the following "sub content" endpoints based on that value (source: cheat sheet provided by LinkedIn).
|content.reference example||sub content endpoint|
For example, my
content.reference value above contains the
share string, so it corresponds to the
https://api.linkedin.com/rest/posts/urn%3Ali%3Ashare%3A6334225903081525248 example endpoint. If I plug in my own reference ID, it returns the ad name.
Ta-da! That's the name of my ad. Hopefully this is useful/interesting for those confused or unsure of how to fetch ad creative names from the new LinkedIn APIs.
Part 4: Handle Pagination
By default, LinkedIn's
/adAnalytics endpoint will return just 1000 records. To return more, apply API Connector's automatic pagination handling as follows
next page URL
- Next page path:
- Run until: choose when to stop fetching data
Part 5: Notes
- Use the visual field editor to re-arrange columns (just click Edit Fields before running your request).
- LinkedIn sends back dates split into separate year, month, and day fields. To transform these into a regular Sheets date, set a data destination of cell B1, and then add the following function into cell A1:
=arrayformula(if(J2:J<>"", date(J2:J,H2:H,I2:I),"")). The function assumes years are in column J, months are in H, and days are in I; adjust as needed.
- To view or manage the connection on LinkedIn, click here: https://www.linkedin.com/psettings/permitted-services
Part 6: API Documentation
Official API documentation: https://docs.microsoft.com/en-us/linkedin/marketing/integrations/ads-reporting/ads-reporting