Linkedin API leads

80 views Asked by At

I am trying to get the leads using the URN of a SponsoredAccount but I get the following error:

{'errorDetailType': 'com.linkedin.common.error.BadRequest', 'message': 'Multiple errors occurred during param validation. Please see errorDetails for more information.', 'errorDetails': {'inputErrors': [{'description': 'ERROR :: /value :: union type is not backed by a DataMap or null', 'input': {'inputPath': {'fieldPath': 'owner/value'}}, 'code': 'FIELD_INVALID'}, {'description': 'Invalid value for field; wrong type or other syntax error', 'input': {'inputPath': {'fieldPath': 'owner/value'}}, 'code': 'FIELD_INVALID'}]}, 'status': 400}

The following is the code with which I have done some tests (I leave the code commented so you can see what I have tested):

#encoded_owner = quote(urn, safe='')
#encoded_owner = quote(f'(sponsoredAccount:{urn})', safe='')

headers = {
    'Authorization': f'Bearer {access_token}',
    'Content-Type': 'application/json',
    "LinkedIn-Version": "202402"
}


#leads_url = f"https://api.linkedin.com/rest/leadForms?owner=(sponsoredAccount:{encoded_owner})&q=owner"
leads_url = f"https://api.linkedin.com/rest/leadForms?owner=(sponsoredAccount:{urn})&q=owner"
#leads_url = f"https://api.linkedin.com/rest/leadForms?owner={encoded_owner}&q=owner"
#leads_url = f'https://api.linkedin.com/rest/leadForms?owner=(sponsoredAccount:urn%3Ali%sponsoredAccount%3A{sponsoredAccount_id})&q=owner&count=10&start=0'

response = requests.get(leads_url, headers=headers)

I don't know what to try anymore, I can't figure out what I'm putting wrong in the request.

This is the link to see the documentation

Thank you very much for your help!

1

There are 1 answers

0
Martinetto On

Thanks for the help, I have found what I was doing wrong. The following code is correct:

import urllib

urn_parsed = urllib.parse.quote(urn)
url = f'https://api.linkedin.com/rest/leadForms?owner=(sponsoredAccount:{urn_parsed})&q=owner&count=1&start=0'
headers = {"Authorization": f"Bearer {access_token}",
      "LinkedIn-Version": "202402",
      "X-Restli-Protocol-Version":"2.0.0"}
response = requests.get(url, headers=headers)
response.json()