LinkedIn营销API创建广告时contentLandingPage等字段未生效求助
Let's break down the issues you're facing with your LinkedIn Marketing API integration—since your basic creative creation works but key fields (contentLandingPage, contentCallToActionLabel) are being ignored, here are the most actionable fixes to try:
1. Fix the Field Nested Hierarchy
LinkedIn's API is extremely strict about field placement, and your current structure likely has the CTA/landing page fields in the wrong level. For SPONSORED_UPDATES with a WEBSITE_VISIT objective, these fields need to be nested under content.structuredContent instead of being top-level under post.
Adjust your creative data structure to match this corrected version:
$data = [ "creative" => [ "inlineContent" => [ "post" => [ "adContext" => [ "dscAdAccount" => "urn:li:sponsoredAccount:" . $this->params->get('app.linkedin_my_acc_id'), "dscStatus" => "ACTIVE" ], "author" => "urn:li:organization:" . $this->params->get('app.linkedin_my_org_id'), "commentary" => $job->getCommentary(), "visibility" => "PUBLIC", "lifecycleState" => "PUBLISHED", "isReshareDisabledByAuthor" => false, "content" => [ "structuredContent" => [ "type" => "WEBSITE", "landingPageUrl" => "https://google.com", // Replaces contentLandingPage "callToAction" => [ "label" => "DOWNLOAD" // Replaces contentCallToActionLabel ], "media" => [ "title" => "This is a test!", "id" => $image ] ] ] ] ], "campaign" => "urn:li:sponsoredCampaign:" . $myCampaignId, "intendedStatus" => "ACTIVE" ] ];
Note that contentLandingPage is replaced by landingPageUrl inside structuredContent, and contentCallToActionLabel becomes callToAction.label—this aligns with LinkedIn's schema for website-focused sponsored content.
2. Verify Campaign & Ad Group Compatibility
Even with a correct creative structure, mismatched settings can cause fields to be ignored:
- Ensure your Ad Group uses a format that supports custom CTAs and landing pages. For
WEBSITE_VISITobjectives, avoid restricted formats that only allow native content links. - Double-check your campaign's
objectiveTypeis explicitly set toWEBSITE_VISIT(confirm via the API's campaign endpoint to rule out typos or sync issues).
3. Validate JSON Encoding in PHP
PHP's default json_encode can sometimes escape characters or mangle fields without throwing errors. When sending your payload, use these flags to ensure proper encoding:
$jsonPayload = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
This prevents unnecessary escaping of URLs and special characters, which could lead LinkedIn to silently ignore the fields.
4. Test with LinkedIn's API Debug Tools
To rule out PHP/cURL-specific issues, test your corrected payload directly using LinkedIn's built-in API console or tools like Postman. If the fields work there, the problem is likely in your PHP code (e.g., missing headers, incorrect authentication, or payload modification before sending).
5. Check API Version & Field Deprecation
You're using the 2023-01 API version, which is valid, but confirm that structuredContent and its child fields are not deprecated for your campaign type. LinkedIn occasionally retires fields without immediate hard errors, so cross-reference the schema for your exact version to ensure compatibility.
内容的提问来源于stack exchange,提问作者HackReb

