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.

feat: add video creative support to create_ad_creative

Yves Junqueirac21954facc90
diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.py
index 00ac6d9..257833f 100644
--- a/meta_ads_mcp/core/ads.py
+++ b/meta_ads_mcp/core/ads.py
@@ -762,6 +762,8 @@ async def create_ad_creative(
description: Optional[str] = None,
descriptions: Optional[List[str]] = None,
image_hashes: Optional[List[str]] = None,
+ video_id: Optional[str] = None,
+ thumbnail_url: Optional[str] = None,
optimization_type: Optional[str] = None,
dynamic_creative_spec: Optional[Dict[str, Any]] = None,
call_to_action_type: Optional[str] = None,
@@ -770,11 +772,17 @@ async def create_ad_creative(
ad_formats: Optional[List[str]] = None
) -> str:
"""
- Create a new ad creative using an uploaded image hash.
+ Create a new ad creative using an uploaded image hash or video ID.
+
+ Supports three creative modes:
+ - **Simple image/video**: Single image_hash or video_id with object_story_spec
+ - **Dynamic Creative**: Multiple variants with dynamic_creative_spec (requires is_dynamic_creative on ad set)
+ - **FLEX/DOF (Advantage+)**: Set optimization_type="DEGREES_OF_FREEDOM" for Meta to auto-optimize
+ across all asset combinations without requiring is_dynamic_creative on the ad set
Args:
account_id: Meta Ads account ID (format: act_XXXXXXXXX)
- image_hash: Hash of a single uploaded image (cannot be used with image_hashes)
+ image_hash: Hash of a single uploaded image (cannot be used with image_hashes or video_id)
access_token: Meta API access token (optional - will use cached token if not provided)
name: Creative name
page_id: Facebook Page ID (string or int; coerced to string)
@@ -785,7 +793,11 @@ async def create_ad_creative(
headlines: List of headlines for dynamic creative testing (cannot be used with headline)
description: Single description for simple ads (cannot be used with descriptions)
descriptions: List of descriptions for dynamic creative testing (cannot be used with description)
- image_hashes: List of image hashes for FLEX creatives (up to 10, cannot be used with image_hash)
+ image_hashes: List of image hashes for FLEX creatives (up to 10, cannot be used with image_hash or video_id)
+ video_id: Meta video ID for video creatives (cannot be used with image_hash or image_hashes).
+ Upload a video first via the Meta API, then use the returned video ID here.
+ thumbnail_url: Thumbnail image URL for video creatives. Recommended when using video_id.
+ Meta will auto-generate a thumbnail if not provided.
optimization_type: Set to "DEGREES_OF_FREEDOM" for FLEX (Advantage+) creatives that allow
Meta to auto-optimize across all asset combinations. When using
DEGREES_OF_FREEDOM, at least one asset field (image_hashes, messages,
@@ -794,11 +806,14 @@ async def create_ad_creative(
call_to_action_type: Call to action button type (e.g., 'LEARN_MORE', 'SIGN_UP', 'SHOP_NOW')
lead_gen_form_id: Lead generation form ID for lead generation campaigns. Required when using
lead generation CTAs like 'SIGN_UP', 'GET_OFFER', 'SUBSCRIBE', etc.
- instagram_actor_id: Optional Instagram account ID for Instagram placements
+ instagram_actor_id: Optional Instagram account ID for Instagram placements.
+ For video creatives, this is placed inside video_data for proper
+ Instagram delivery.
ad_formats: List of ad format strings for asset_feed_spec (e.g., ["AUTOMATIC_FORMAT"] for
- Flexible ads, ["SINGLE_IMAGE"] for single image). When optimization_type is
- "DEGREES_OF_FREEDOM" with image_hashes, defaults to ["AUTOMATIC_FORMAT"]
- (Flexible format). Otherwise defaults to ["SINGLE_IMAGE"].
+ Flexible ads, ["SINGLE_IMAGE"] for single image, ["SINGLE_VIDEO"] for video).
+ When optimization_type is "DEGREES_OF_FREEDOM" with image_hashes, defaults to
+ ["AUTOMATIC_FORMAT"] (Flexible format). For video creatives, defaults to
+ ["SINGLE_VIDEO"]. Otherwise defaults to ["SINGLE_IMAGE"].
Returns:
JSON response with created creative details
@@ -833,28 +848,34 @@ async def create_ad_creative(
pass
logger.debug(
- "create_ad_creative called: image_hash=%s, image_hashes=%s(%s), "
+ "create_ad_creative called: image_hash=%s, image_hashes=%s(%s), video_id=%s, "
"messages=%s, headlines=%s, descriptions=%s, optimization_type=%s",
type(image_hash).__name__,
type(image_hashes).__name__, image_hashes,
+ video_id,
type(messages).__name__,
type(headlines).__name__,
type(descriptions).__name__,
optimization_type,
)
- # Validate image_hash / image_hashes mutual exclusivity
- if image_hash and image_hashes:
- return json.dumps({"error": "Cannot specify both 'image_hash' and 'image_hashes'. Use 'image_hash' for a single image or 'image_hashes' for multiple."}, indent=2)
+ # Validate media mutual exclusivity: exactly one of image_hash, image_hashes, or video_id
+ media_params = sum(1 for x in [image_hash, image_hashes, video_id] if x)
+ if media_params > 1:
+ return json.dumps({"error": "Only one media source allowed. Use 'image_hash' for a single image, 'image_hashes' for multiple images, or 'video_id' for video."}, indent=2)
- if not image_hash and not image_hashes:
- return json.dumps({"error": "No image hash provided. Specify 'image_hash' for a single image or 'image_hashes' for multiple."}, indent=2)
+ if media_params == 0:
+ return json.dumps({"error": "No media provided. Specify 'image_hash' for a single image, 'image_hashes' for multiple images, or 'video_id' for a video."}, indent=2)
# Validate image_hashes limits
if image_hashes:
if len(image_hashes) > 10:
return json.dumps({"error": "Maximum 10 image hashes allowed for FLEX creatives"}, indent=2)
+ # Validate thumbnail_url only with video_id
+ if thumbnail_url and not video_id:
+ return json.dumps({"error": "thumbnail_url can only be used with video_id"}, indent=2)
+
# Validate optimization_type
if optimization_type and optimization_type != "DEGREES_OF_FREEDOM":
return json.dumps({"error": f"Invalid optimization_type '{optimization_type}'. Only 'DEGREES_OF_FREEDOM' is supported."}, indent=2)
@@ -939,18 +960,26 @@ async def create_ad_creative(
# - optimization_type is set (FLEX creatives always use asset_feed_spec)
use_asset_feed = bool(headlines or descriptions or messages or image_hashes or optimization_type)
+ # Track if this is a video creative
+ is_video = bool(video_id)
+
if use_asset_feed:
- # Build the images array from image_hashes (plural) or image_hash (singular)
- if image_hashes:
+ # Build the media array from the provided source
+ if is_video:
+ # Video in asset_feed_spec uses "videos" key
+ videos_array = [{"video_id": video_id}]
+ if thumbnail_url:
+ videos_array[0]["thumbnail_url"] = thumbnail_url
+ elif image_hashes:
images_array = [{"hash": h} for h in image_hashes]
else:
images_array = [{"hash": image_hash}]
# Determine ad_formats: use explicit value if provided, otherwise smart default.
- # When using DEGREES_OF_FREEDOM with image_hashes, default to AUTOMATIC_FORMAT
- # ("Flexible" in Ads Manager) so Meta can optimize across format variants.
if ad_formats:
resolved_ad_formats = ad_formats
+ elif is_video:
+ resolved_ad_formats = ["SINGLE_VIDEO"]
elif optimization_type == "DEGREES_OF_FREEDOM" and image_hashes:
resolved_ad_formats = ["AUTOMATIC_FORMAT"]
else:
@@ -958,11 +987,16 @@ async def create_ad_creative(
# Use asset_feed_spec for dynamic/FLEX creatives with multiple variants
asset_feed_spec = {
- "images": images_array,
"link_urls": [{"website_url": link_url}],
"ad_formats": resolved_ad_formats
}
+ # Add media to asset_feed_spec
+ if is_video:
+ asset_feed_spec["videos"] = videos_array
+ else:
+ asset_feed_spec["images"] = images_array
+
# Add optimization_type for FLEX (Advantage+) creatives
if optimization_type:
asset_feed_spec["optimization_type"] = optimization_type
@@ -994,50 +1028,96 @@ async def create_ad_creative(
creative_data["asset_feed_spec"] = asset_feed_spec
# For dynamic/FLEX creatives with asset_feed_spec, object_story_spec still
- # needs page_id and a link_data.link (Meta API requires the link field).
- creative_data["object_story_spec"] = {
- "page_id": page_id,
- "link_data": {
- "link": link_url
+ # needs page_id and a media anchor (Meta API requires this).
+ if is_video:
+ creative_data["object_story_spec"] = {
+ "page_id": page_id,
+ "video_data": {
+ "video_id": video_id,
+ "link": link_url
+ }
+ }
+ else:
+ creative_data["object_story_spec"] = {
+ "page_id": page_id,
+ "link_data": {
+ "link": link_url
+ }
}
- }
else:
- # Use traditional object_story_spec with link_data for simple creatives
- creative_data["object_story_spec"] = {
- "page_id": page_id,
- "link_data": {
- "image_hash": image_hash,
+ if is_video:
+ # Use object_story_spec with video_data for simple video creatives
+ video_data = {
+ "video_id": video_id,
"link": link_url
}
- }
- # Add optional parameters if provided
- if message:
- creative_data["object_story_spec"]["link_data"]["message"] = message
+ if thumbnail_url:
+ video_data["image_url"] = thumbnail_url
- # Add headline (singular) to link_data
- if headline:
- creative_data["object_story_spec"]["link_data"]["name"] = headline
+ if message:
+ video_data["message"] = message
- # Add description (singular) to link_data
- if description:
- creative_data["object_story_spec"]["link_data"]["description"] = description
+ if headline:
+ video_data["title"] = headline
- # Add call_to_action to link_data for simple creatives
- if call_to_action_type:
- cta_data = {"type": call_to_action_type}
+ if description:
+ video_data["description"] = description
- # Add lead form ID to value object if provided (required for lead generation campaigns)
- if lead_gen_form_id:
- cta_data["value"] = {"lead_gen_form_id": lead_gen_form_id}
+ if call_to_action_type:
+ cta_data = {"type": call_to_action_type}
+ if lead_gen_form_id:
+ cta_data["value"] = {"lead_gen_form_id": lead_gen_form_id}
+ video_data["call_to_action"] = cta_data
+
+ # Instagram actor ID goes inside video_data for proper Instagram delivery
+ if instagram_actor_id:
+ video_data["instagram_actor_id"] = instagram_actor_id
+
+ creative_data["object_story_spec"] = {
+ "page_id": page_id,
+ "video_data": video_data
+ }
+ else:
+ # Use traditional object_story_spec with link_data for simple image creatives
+ creative_data["object_story_spec"] = {
+ "page_id": page_id,
+ "link_data": {
+ "image_hash": image_hash,
+ "link": link_url
+ }
+ }
+
+ # Add optional parameters if provided
+ if message:
+ creative_data["object_story_spec"]["link_data"]["message"] = message
+
+ # Add headline (singular) to link_data
+ if headline:
+ creative_data["object_story_spec"]["link_data"]["name"] = headline
+
+ # Add description (singular) to link_data
+ if description:
+ creative_data["object_story_spec"]["link_data"]["description"] = description
+
+ # Add call_to_action to link_data for simple creatives
+ if call_to_action_type:
+ cta_data = {"type": call_to_action_type}
+
+ # Add lead form ID to value object if provided (required for lead generation campaigns)
+ if lead_gen_form_id:
+ cta_data["value"] = {"lead_gen_form_id": lead_gen_form_id}
- creative_data["object_story_spec"]["link_data"]["call_to_action"] = cta_data
+ creative_data["object_story_spec"]["link_data"]["call_to_action"] = cta_data
# Add dynamic creative spec if provided
if dynamic_creative_spec:
creative_data["dynamic_creative_spec"] = dynamic_creative_spec
- if instagram_actor_id:
+ # For non-video creatives, instagram_actor_id goes at the top level.
+ # For video creatives in the simple path, it's already inside video_data above.
+ # For video creatives in the asset_feed_spec path, it goes at the top level.
+ if instagram_actor_id and (not is_video or use_asset_feed):
creative_data["instagram_actor_id"] = instagram_actor_id
# Make API request to create the creative
diff --git a/tests/test_flex_creatives.py b/tests/test_flex_creatives.py
index 6033cc7..4e8fbbc 100644
--- a/tests/test_flex_creatives.py
+++ b/tests/test_flex_creatives.py
@@ -138,10 +138,10 @@ class TestFlexCreatives:
if "data" in result_data:
error_data = json.loads(result_data["data"])
assert "error" in error_data
- assert "Cannot specify both 'image_hash' and 'image_hashes'" in error_data["error"]
+ assert "Only one media source" in error_data["error"]
else:
assert "error" in result_data
- assert "Cannot specify both 'image_hash' and 'image_hashes'" in result_data["error"]
+ assert "Only one media source" in result_data["error"]
async def test_validation_cannot_mix_message_and_messages(self):
"""Cannot specify both message and messages."""
@@ -355,7 +355,7 @@ class TestFlexCreatives:
assert "optimization_type" not in creative_data["asset_feed_spec"]
async def test_no_image_hash_or_image_hashes_returns_error(self):
- """Must provide either image_hash or image_hashes."""
+ """Must provide either image_hash, image_hashes, or video_id."""
result = await create_ad_creative(
access_token="test_token",
account_id="act_123456789",
@@ -367,10 +367,10 @@ class TestFlexCreatives:
if "data" in result_data:
error_data = json.loads(result_data["data"])
assert "error" in error_data
- assert "image hash" in error_data["error"].lower()
+ assert "no media provided" in error_data["error"].lower()
else:
assert "error" in result_data
- assert "image hash" in result_data["error"].lower()
+ assert "no media provided" in result_data["error"].lower()
@pytest.mark.asyncio
diff --git a/tests/test_video_creatives.py b/tests/test_video_creatives.py
new file mode 100644
index 0000000..15e7933
--- /dev/null
+++ b/tests/test_video_creatives.py
@@ -0,0 +1,375 @@
+"""Test that create_ad_creative handles video creatives correctly."""
+
+import pytest
+import json
+from unittest.mock import AsyncMock, patch
+from meta_ads_mcp.core.ads import create_ad_creative
+
+
+def parse_error_result(result: str) -> dict:
+ """Parse error result from create_ad_creative, handling decorator wrapping.
+
+ The meta_api_tool decorator has a known quirk where validation errors without
+ a 'details' key get wrapped in {"data": "<json_string>"} due to a KeyError
+ in the error inspection code. This helper unwraps both formats.
+ """
+ data = json.loads(result)
+ if "data" in data and isinstance(data["data"], str):
+ return json.loads(data["data"])
+ return data
+
+
+async def test_simple_video_creative_uses_video_data():
+ """Test that video_id creates a simple creative with object_story_spec.video_data."""
+
+ with patch('meta_ads_mcp.core.ads.make_api_request') as mock_api, \
+ patch('meta_ads_mcp.core.ads._discover_pages_for_account') as mock_discover:
+
+ mock_discover.return_value = {
+ "success": True,
+ "page_id": "123456789",
+ "page_name": "Test Page"
+ }
+
+ mock_api.side_effect = [
+ {"id": "creative_vid_1"},
+ {"id": "creative_vid_1", "name": "Video Creative", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ video_id="vid_987654",
+ name="Video Ad",
+ link_url="https://example.com/",
+ message="Check out this video",
+ headline="Watch Now",
+ description="Amazing content",
+ call_to_action_type="LEARN_MORE",
+ access_token="test_token"
+ )
+
+ assert mock_api.call_count == 2
+
+ creative_data = mock_api.call_args_list[0][0][2]
+
+ # Should use object_story_spec with video_data, NOT link_data
+ assert "object_story_spec" in creative_data
+ assert "asset_feed_spec" not in creative_data
+ assert "video_data" in creative_data["object_story_spec"]
+ assert "link_data" not in creative_data["object_story_spec"]
+
+ video_data = creative_data["object_story_spec"]["video_data"]
+ assert video_data["video_id"] == "vid_987654"
+ assert video_data["link"] == "https://example.com/"
+ assert video_data["message"] == "Check out this video"
+ assert video_data["title"] == "Watch Now"
+ assert video_data["description"] == "Amazing content"
+ assert video_data["call_to_action"]["type"] == "LEARN_MORE"
+
+
+async def test_video_creative_with_thumbnail():
+ """Test that thumbnail_url is included as image_url in video_data."""
+
+ with patch('meta_ads_mcp.core.ads.make_api_request') as mock_api, \
+ patch('meta_ads_mcp.core.ads._discover_pages_for_account') as mock_discover:
+
+ mock_discover.return_value = {
+ "success": True,
+ "page_id": "123456789",
+ "page_name": "Test Page"
+ }
+
+ mock_api.side_effect = [
+ {"id": "creative_vid_2"},
+ {"id": "creative_vid_2", "name": "Video With Thumb", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ video_id="vid_111222",
+ thumbnail_url="https://example.com/thumb.jpg",
+ name="Video With Thumbnail",
+ link_url="https://example.com/",
+ access_token="test_token"
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+ video_data = creative_data["object_story_spec"]["video_data"]
+
+ assert video_data["image_url"] == "https://example.com/thumb.jpg"
+ assert video_data["video_id"] == "vid_111222"
+
+
+async def test_video_creative_with_instagram_actor_id():
+ """Test that instagram_actor_id goes inside video_data for simple video creatives."""
+
+ with patch('meta_ads_mcp.core.ads.make_api_request') as mock_api, \
+ patch('meta_ads_mcp.core.ads._discover_pages_for_account') as mock_discover:
+
+ mock_discover.return_value = {
+ "success": True,
+ "page_id": "123456789",
+ "page_name": "Test Page"
+ }
+
+ mock_api.side_effect = [
+ {"id": "creative_vid_3"},
+ {"id": "creative_vid_3", "name": "Video IG", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ video_id="vid_333444",
+ name="Video For Instagram",
+ link_url="https://example.com/",
+ instagram_actor_id="ig_555666",
+ access_token="test_token"
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+ video_data = creative_data["object_story_spec"]["video_data"]
+
+ # For simple video creatives, instagram_actor_id should be inside video_data
+ assert video_data["instagram_actor_id"] == "ig_555666"
+ # And NOT at the top level
+ assert "instagram_actor_id" not in creative_data
+
+
+async def test_video_creative_asset_feed_spec_path():
+ """Test video creative with plural params triggers asset_feed_spec with videos array."""
+
+ with patch('meta_ads_mcp.core.ads.make_api_request') as mock_api, \
+ patch('meta_ads_mcp.core.ads._discover_pages_for_account') as mock_discover:
+
+ mock_discover.return_value = {
+ "success": True,
+ "page_id": "123456789",
+ "page_name": "Test Page"
+ }
+
+ mock_api.side_effect = [
+ {"id": "creative_vid_4"},
+ {"id": "creative_vid_4", "name": "Video FLEX", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ video_id="vid_555666",
+ name="Video FLEX Creative",
+ link_url="https://example.com/",
+ headlines=["Headline A", "Headline B"],
+ messages=["Body text 1", "Body text 2"],
+ thumbnail_url="https://example.com/thumb.jpg",
+ access_token="test_token"
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+
+ # Should use asset_feed_spec
+ assert "asset_feed_spec" in creative_data
+ afs = creative_data["asset_feed_spec"]
+
+ # Should have videos array, NOT images array
+ assert "videos" in afs
+ assert "images" not in afs
+ assert afs["videos"] == [{"video_id": "vid_555666", "thumbnail_url": "https://example.com/thumb.jpg"}]
+
+ # Default ad_formats for video should be SINGLE_VIDEO
+ assert afs["ad_formats"] == ["SINGLE_VIDEO"]
+
+ # Should have titles and bodies
+ assert len(afs["titles"]) == 2
+ assert len(afs["bodies"]) == 2
+
+ # object_story_spec should use video_data anchor
+ assert "video_data" in creative_data["object_story_spec"]
+ assert creative_data["object_story_spec"]["video_data"]["video_id"] == "vid_555666"
+
+
+async def test_video_creative_with_dof_optimization():
+ """Test video creative with DEGREES_OF_FREEDOM optimization_type."""
+
+ with patch('meta_ads_mcp.core.ads.make_api_request') as mock_api, \
+ patch('meta_ads_mcp.core.ads._discover_pages_for_account') as mock_discover:
+
+ mock_discover.return_value = {
+ "success": True,
+ "page_id": "123456789",
+ "page_name": "Test Page"
+ }
+
+ mock_api.side_effect = [
+ {"id": "creative_vid_5"},
+ {"id": "creative_vid_5", "name": "Video DOF", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ video_id="vid_777888",
+ name="Video DOF Creative",
+ link_url="https://example.com/",
+ optimization_type="DEGREES_OF_FREEDOM",
+ messages=["Text variant 1", "Text variant 2"],
+ access_token="test_token"
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+ afs = creative_data["asset_feed_spec"]
+
+ assert afs["optimization_type"] == "DEGREES_OF_FREEDOM"
+ assert "videos" in afs
+ assert afs["videos"] == [{"video_id": "vid_777888"}]
+
+
+async def test_video_and_image_hash_mutual_exclusivity():
+ """Test that providing both video_id and image_hash returns an error."""
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ video_id="vid_123",
+ image_hash="hash_456",
+ name="Should Fail",
+ link_url="https://example.com/",
+ access_token="test_token"
+ )
+
+ data = parse_error_result(result)
+ assert "error" in data
+ assert "Only one media source" in data["error"]
+
+
+async def test_video_and_image_hashes_mutual_exclusivity():
+ """Test that providing both video_id and image_hashes returns an error."""
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ video_id="vid_123",
+ image_hashes=["hash_1", "hash_2"],
+ name="Should Fail",
+ link_url="https://example.com/",
+ access_token="test_token"
+ )
+
+ data = parse_error_result(result)
+ assert "error" in data
+ assert "Only one media source" in data["error"]
+
+
+async def test_thumbnail_without_video_returns_error():
+ """Test that providing thumbnail_url without video_id returns an error."""
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ image_hash="hash_123",
+ thumbnail_url="https://example.com/thumb.jpg",
+ name="Should Fail",
+ link_url="https://example.com/",
+ access_token="test_token"
+ )
+
+ data = parse_error_result(result)
+ assert "error" in data
+ assert "thumbnail_url can only be used with video_id" in data["error"]
+
+
+async def test_no_media_returns_error():
+ """Test that providing no media source returns an error."""
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ name="Should Fail",
+ link_url="https://example.com/",
+ access_token="test_token"
+ )
+
+ data = parse_error_result(result)
+ assert "error" in data
+ assert "No media provided" in data["error"]
+
+
+async def test_video_creative_with_lead_gen():
+ """Test video creative with lead generation form ID."""
+
+ with patch('meta_ads_mcp.core.ads.make_api_request') as mock_api, \
+ patch('meta_ads_mcp.core.ads._discover_pages_for_account') as mock_discover:
+
+ mock_discover.return_value = {
+ "success": True,
+ "page_id": "123456789",
+ "page_name": "Test Page"
+ }
+
+ mock_api.side_effect = [
+ {"id": "creative_vid_lead"},
+ {"id": "creative_vid_lead", "name": "Video Lead Gen", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ video_id="vid_leadgen",
+ name="Video Lead Gen Creative",
+ link_url="https://example.com/",
+ call_to_action_type="SIGN_UP",
+ lead_gen_form_id="form_12345",
+ access_token="test_token"
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+ video_data = creative_data["object_story_spec"]["video_data"]
+
+ assert video_data["call_to_action"]["type"] == "SIGN_UP"
+ assert video_data["call_to_action"]["value"]["lead_gen_form_id"] == "form_12345"
+
+
+async def test_image_creative_still_works():
+ """Regression test: existing image creative path should still work unchanged."""
+
+ with patch('meta_ads_mcp.core.ads.make_api_request') as mock_api, \
+ patch('meta_ads_mcp.core.ads._discover_pages_for_account') as mock_discover:
+
+ mock_discover.return_value = {
+ "success": True,
+ "page_id": "123456789",
+ "page_name": "Test Page"
+ }
+
+ mock_api.side_effect = [
+ {"id": "creative_img_1"},
+ {"id": "creative_img_1", "name": "Image Creative", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_123456",
+ image_hash="hash_abc123",
+ name="Image Ad",
+ link_url="https://example.com/",
+ message="Click here",
+ headline="Great Offer",
+ call_to_action_type="SHOP_NOW",
+ access_token="test_token"
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+
+ # Should use link_data, NOT video_data
+ assert "link_data" in creative_data["object_story_spec"]
+ assert "video_data" not in creative_data["object_story_spec"]
+
+ link_data = creative_data["object_story_spec"]["link_data"]
+ assert link_data["image_hash"] == "hash_abc123"
+ assert link_data["link"] == "https://example.com/"
+ assert link_data["message"] == "Click here"
+
+ # instagram_actor_id at top level for image creatives
+ assert "instagram_actor_id" not in creative_data