使用SponsoredAccount URN调用LinkedIn API获销售线索报400错误求助
问题:通过SponsoredAccount URN调用LinkedIn API获取销售线索时遭遇400错误
调用LinkedIn API获取销售线索时,传入SponsoredAccount的URN后收到以下400错误:
{ "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 }
以下是测试过的代码(包含多种尝试写法的注释):
# 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)
排查建议
- 检查URN完整性:确保
urn变量是完整的SponsoredAccount URN,格式为urn:li:sponsoredAccount:{账号ID},不能仅传入数字ID。 - 避免多余编码:
owner参数需使用未编码的结构化格式(sponsoredAccount:{完整URN}),不需要对整个结构或URN做URL编码。 - 核对参数格式:直接硬编码正确格式的URN进行测试(如
owner=(sponsoredAccount:urn:li:sponsoredAccount:123456)),排除变量替换错误。 - 验证权限与版本:确认
access_token拥有r_leadgen_automation或rw_ads权限,且LinkedIn-Version与文档要求的202402一致。
内容的提问来源于stack exchange,提问作者Martinetto
相关产品推荐
相关产品推荐

