Skip to content

Meta Ads (Facebook/Instagram) MCP server for Claude, ChatGPT, Perplexity & Cursor — the Meta node of Pipeboard’s 5-platform family (+ Google, TikTok, Snap, Reddit). Hosted remote MCP, badged Meta Business Partner, free plan — no self-hosting required.

Omit link_data from object_story_spec for non-DOF asset_feed_spec creatives (#44)

Yves Junqueira43389bbb8e55
diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.py
index 46d16db..c46c2d7 100644
--- a/meta_ads_mcp/core/ads.py
+++ b/meta_ads_mcp/core/ads.py
@@ -1510,27 +1510,35 @@ async def create_ad_creative(
"video_data": video_anchor
}
else:
- # Image creative: build link_data anchor.
- link_data = {"link": link_url}
- if image_hashes:
- link_data["image_hash"] = image_hashes[0]
- # DOF: put CTA in link_data (not in asset_feed_spec)
- if optimization_type and call_to_action_type:
- cta = {"type": call_to_action_type}
- cta_value = {}
- if link_url:
- cta_value["link"] = link_url
- if lead_gen_form_id:
- cta_value["lead_gen_form_id"] = lead_gen_form_id
- if phone_number:
- cta_value["phone_number"] = phone_number
- if cta_value:
- cta["value"] = cta_value
- link_data["call_to_action"] = cta
- creative_data["object_story_spec"] = {
- "page_id": page_id,
- "link_data": link_data,
- }
+ if not optimization_type:
+ # Non-DOF asset_feed_spec: Meta requires bare
+ # object_story_spec (no link_data). URLs, images, CTA
+ # live exclusively in asset_feed_spec.
+ # Ref: developers.facebook.com/docs/marketing-api/asset-customization-rules
+ creative_data["object_story_spec"] = {
+ "page_id": page_id,
+ }
+ else:
+ # DOF: link_data serves as the "anchor" creative template.
+ link_data = {"link": link_url}
+ if image_hashes:
+ link_data["image_hash"] = image_hashes[0]
+ if call_to_action_type:
+ cta = {"type": call_to_action_type}
+ cta_value = {}
+ if link_url:
+ cta_value["link"] = link_url
+ if lead_gen_form_id:
+ cta_value["lead_gen_form_id"] = lead_gen_form_id
+ if phone_number:
+ cta_value["phone_number"] = phone_number
+ if cta_value:
+ cta["value"] = cta_value
+ link_data["call_to_action"] = cta
+ creative_data["object_story_spec"] = {
+ "page_id": page_id,
+ "link_data": link_data,
+ }
else:
if is_video:
# Use object_story_spec with video_data for simple video creatives.
diff --git a/tests/test_flex_creatives.py b/tests/test_flex_creatives.py
index 7bc546d..4d9a9b9 100644
--- a/tests/test_flex_creatives.py
+++ b/tests/test_flex_creatives.py
@@ -370,11 +370,10 @@ class TestFlexCreatives:
# No optimization_type should be set
assert "optimization_type" not in creative_data["asset_feed_spec"]
- # Multi-image: link_data must include image_hash as primary anchor
- assert creative_data["object_story_spec"] == {
- "page_id": "987654321",
- "link_data": {"link": "https://example.com", "image_hash": "hash1"},
- }
+ # Non-DOF: object_story_spec must NOT contain link_data;
+ # URLs, images, CTA live exclusively in asset_feed_spec.
+ assert creative_data["object_story_spec"]["page_id"] == "987654321"
+ assert "link_data" not in creative_data["object_story_spec"]
async def test_no_image_hash_or_image_hashes_returns_error(self):
"""Must provide either image_hash, image_hashes, or video_id."""