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.

fix: include link URL in object_story_spec for video FLEX creatives

Yves Junqueira32f22d0c1dc7
diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.py
index 2120707..a4590ca 100644
--- a/meta_ads_mcp/core/ads.py
+++ b/meta_ads_mcp/core/ads.py
@@ -242,7 +242,7 @@ async def get_creative_details(creative_id: str, access_token: Optional[str] = N
# "(#100) Tried accessing nonexisting field" on simple creatives in API v24.
# We fetch the safe fields first, then try dynamic_creative_spec separately.
params = {
- "fields": "id,name,status,thumbnail_url,image_url,image_hash,object_story_spec,asset_feed_spec,url_tags,link_url"
+ "fields": "id,name,status,thumbnail_url,image_url,image_hash,object_story_spec,asset_feed_spec{images,videos,bodies,titles,descriptions,link_urls,ad_formats,call_to_action_types,optimization_type},url_tags,link_url"
}
data = await make_api_request(endpoint, access_token, params)
@@ -1256,22 +1256,36 @@ async def create_ad_creative(
creative_data["asset_feed_spec"] = asset_feed_spec
- # For dynamic/FLEX creatives with asset_feed_spec, object_story_spec needs
- # page_id. For non-video, the link URL is already in asset_feed_spec.link_urls
- # so link_data is NOT added here (Meta rejects link_data without image_hash).
+ # For asset_feed_spec creatives, object_story_spec needs page_id
+ # plus a link anchor. Meta rejects bare page_id (error 2061015).
if is_video:
- # video_data does NOT support "link" directly — URL goes in
- # call_to_action.value.link or is handled by asset_feed_spec.link_urls.
+ # Video FLEX: use video_data with call_to_action carrying
+ # the link URL. This is required for Meta to associate the
+ # video and destination URL with the creative.
video_anchor = {"video_id": video_id}
if thumbnail_url:
video_anchor["image_url"] = thumbnail_url
+ cta_type = call_to_action_type or "LEARN_MORE"
+ 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
+ cta_data = {"type": cta_type}
+ if cta_value:
+ cta_data["value"] = cta_value
+ video_anchor["call_to_action"] = cta_data
creative_data["object_story_spec"] = {
"page_id": page_id,
"video_data": video_anchor
}
else:
+ # Image FLEX: use link_data with the destination URL.
creative_data["object_story_spec"] = {
- "page_id": page_id
+ "page_id": page_id,
+ "link_data": {
+ "link": link_url
+ }
}
else:
if is_video:
@@ -1391,7 +1405,7 @@ async def create_ad_creative(
creative_id = data["id"]
creative_endpoint = f"{creative_id}"
creative_params = {
- "fields": "id,name,status,thumbnail_url,image_url,image_hash,object_story_spec,asset_feed_spec,url_tags,link_url"
+ "fields": "id,name,status,thumbnail_url,image_url,image_hash,object_story_spec,asset_feed_spec{images,videos,bodies,titles,descriptions,link_urls,ad_formats,call_to_action_types,optimization_type},url_tags,link_url"
}
creative_details = await make_api_request(creative_endpoint, access_token, creative_params)
diff --git a/tests/test_ad_formats_flexible.py b/tests/test_ad_formats_flexible.py
index f723bdc..a866317 100644
--- a/tests/test_ad_formats_flexible.py
+++ b/tests/test_ad_formats_flexible.py
@@ -284,9 +284,10 @@ class TestFlexibleCreativeFullFlow:
assert afs["call_to_action_types"] == ["SHOP_NOW"]
assert afs["link_urls"] == [{"website_url": "https://example.com"}]
- # object_story_spec needs only page_id; link URL is in asset_feed_spec.link_urls
+ # object_story_spec needs page_id + link_data with destination URL
assert creative_data["object_story_spec"] == {
- "page_id": "987654321"
+ "page_id": "987654321",
+ "link_data": {"link": "https://example.com"}
}
async def test_backward_compat_simple_creative_unaffected(self):
diff --git a/tests/test_flex_creatives.py b/tests/test_flex_creatives.py
index dfb71d9..23b9f88 100644
--- a/tests/test_flex_creatives.py
+++ b/tests/test_flex_creatives.py
@@ -238,9 +238,11 @@ class TestFlexCreatives:
assert "asset_feed_spec" in creative_data
assert creative_data["asset_feed_spec"]["images"] == [{"hash": "abc123"}]
assert creative_data["asset_feed_spec"]["optimization_type"] == "DEGREES_OF_FREEDOM"
- # object_story_spec needs only page_id; link URL is already in asset_feed_spec.link_urls
+ # object_story_spec needs page_id + link_data with destination URL
+ # (Meta rejects object_story_spec without link — error 2061015)
assert creative_data["object_story_spec"] == {
- "page_id": "987654321"
+ "page_id": "987654321",
+ "link_data": {"link": "https://example.com"}
}
async def test_no_optimization_type_unchanged_behavior(self):
diff --git a/tests/test_video_creatives.py b/tests/test_video_creatives.py
index c4eb657..a10decc 100644
--- a/tests/test_video_creatives.py
+++ b/tests/test_video_creatives.py
@@ -202,10 +202,13 @@ async def test_video_creative_asset_feed_spec_path():
assert len(afs["titles"]) == 2
assert len(afs["bodies"]) == 2
- # object_story_spec should use video_data anchor without "link"
+ # Video FLEX: object_story_spec uses video_data with call_to_action
assert "video_data" in creative_data["object_story_spec"]
- assert creative_data["object_story_spec"]["video_data"]["video_id"] == "vid_555666"
- assert "link" not in creative_data["object_story_spec"]["video_data"]
+ vd = creative_data["object_story_spec"]["video_data"]
+ assert vd["video_id"] == "vid_555666"
+ assert "link" not in vd, "link must NOT be in video_data directly"
+ assert vd["call_to_action"]["type"] == "LEARN_MORE"
+ assert vd["call_to_action"]["value"]["link"] == "https://example.com/"
@pytest.mark.asyncio
@@ -248,9 +251,13 @@ async def test_video_creative_with_dof_optimization():
# Auto-fetched thumbnail should be included in videos array
assert afs["videos"] == [{"video_id": "vid_777888", "thumbnail_url": "https://example.com/auto-thumb.jpg"}]
- # video_data anchor should have image_url and not "link"
- assert creative_data["object_story_spec"]["video_data"]["image_url"] == "https://example.com/auto-thumb.jpg"
- assert "link" not in creative_data["object_story_spec"]["video_data"]
+ # Video FLEX: video_data anchor with call_to_action
+ assert "video_data" in creative_data["object_story_spec"]
+ vd = creative_data["object_story_spec"]["video_data"]
+ assert vd["image_url"] == "https://example.com/auto-thumb.jpg"
+ assert "link" not in vd
+ assert vd["call_to_action"]["type"] == "LEARN_MORE"
+ assert vd["call_to_action"]["value"]["link"] == "https://example.com/"
@pytest.mark.asyncio