linkedin-api

LinkedIn adAnalytics API - http 500 errors when matching by companies facet


I am using the LinkedIn Ads Reporting API to retrieve the number of impressions, members targeted and engagement data for each company in my audience list.

I am able to pivot by MEMBER_COMPANY and easily get all data, except the approximateMemberReach metric. The documentation explicitly says: "Non-demographic pivots only (i.e. not MEMBER_). ".

What I am trying to do to circumvent this is to retrieve the company list first, and then call the API once for each company in the list, matching the company ID.

However, when I try to apply the companies facet, I get HTTP 500.


fields = [
  "approximateMemberReach",
  "impressions",
  "pivotValues"
]

url = f"https://api.linkedin.com/rest/adAnalytics?q=analytics&companies=List(urn%3Ali%3Aorganization%3A{company_id})&pivot=CAMPAIGN&timeGranularity=ALL&dateRange=(start:(day:{start_day},month:{start_month},year:{start_year}),end:(day:{end_day},month:{end_month},year:{end_year}))&accounts=List(urn%3Ali%3AsponsoredAccount%3A{account_id})&fields={','.join(fields)}"

headers = {
  'LinkedIn-Version': '202405',
  'X-Restli-Protocol-Version': '2.0.0',
  'Authorization': f"Bearer {token}",
}

response = requests.request("GET", url, headers=headers)

print(response.text)

If I remove the companies=List(org URN) param above, it works as expected. The HTTP response doesn't provide any ideas on what is wrong, it just returns 500 Server Error.

Any ideas?


Solution

  • After contacting the LinkedIn API support (https://linkedin.zendesk.com/), they asked me to replace urn:li:organization with urn:li:company and it worked as expected