restcurlhttp-headerslinkedin-api

LinkedIn API 400 bad request


I am trying to add an Ad Account User.

I've tried the request as below, and with with URN. Both give me the error:

compound key parameter value is invalid

curl --request PUT \
   --url https://api.linkedin.com/rest/adAccountUsers/account=123456789&user=ABCABCABCAB \
   --header 'Authorization: Bearer xxxxx' \
   --header 'Content-Type: application/json' \
   --header 'LinkedIn-Version: 202501' \
   --data '{    "account": "urn:li:sponsoredAccount:123456789",     "role": "ACCOUNT_MANAGER",  "user": "urn:li:person:ABCABCABCAB" }'

When I try adding the header X-Restli-Protocol-Version: 2.0.0, the error changes to:

ILLEGAL ARGUMENT: Syntax exception in path variables.

I have tried copying the sample request and just changing the URN/id's of the sponsoredAccount and person but that still gives the same result.

What can I do to fix this?


Solution

  • I managed to fix it. The solution was to wrap the path variables in parenthesis and encoding a few of the ":" in the path as well as using a comma instead of ampersand between the variables.

    Documentation example: https://api.linkedin.com/rest/adAccountUsers/account=123456789&user=ABCABCABCAB

    Working: https://api.linkedin.com/rest/adAccountUsers/(account:urn%3Ali%3AsponsoredAccount%3A123456789,user:urn%3Ali%3Aperson%3AABCABCABCAB)