Support promoting existing FB/IG posts in create_ad_creative

Add object_story_id for reusing a Facebook Page post as-is, and
instagram_user_id/source_instagram_media_id for reusing an existing
Instagram post — both bypass building a new object_story_spec.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5 committed 2026-08-16 22:58:09 +02:00
1 parent e902547be8
commit d1352752df
1 file changed
+47 -25
+47 -25
View File
@@ -271,7 +271,7 @@ def get_ad_creative(creative_id: str) -> dict:
@mcp.tool() @mcp.tool()
def create_ad_creative( def create_ad_creative(
name: str, name: str,
page_id: str, page_id: str | None = None,
ad_account_id: str | None = None, ad_account_id: str | None = None,
message: str | None = None, message: str | None = None,
link: str | None = None, link: str | None = None,
@@ -280,36 +280,58 @@ def create_ad_creative(
call_to_action_type: str | None = None, call_to_action_type: str | None = None,
headline: str | None = None, headline: str | None = None,
description: str | None = None, description: str | None = None,
object_story_id: str | None = None,
instagram_user_id: str | None = None,
source_instagram_media_id: str | None = None,
) -> dict: ) -> dict:
"""Create an ad creative for a link/image or video ad, backed by a Facebook """Create an ad creative for a link/image or video ad, backed by a Facebook
Page (page_id). Use upload_ad_image/upload_ad_video first to get image_hash/ Page (page_id). Use upload_ad_image/upload_ad_video first to get image_hash/
video_id. call_to_action_type is e.g. 'LEARN_MORE', 'SHOP_NOW', 'SIGN_UP'.""" video_id. call_to_action_type is e.g. 'LEARN_MORE', 'SHOP_NOW', 'SIGN_UP'.
link_data: dict = {}
if message is not None:
link_data["message"] = message
if link is not None:
link_data["link"] = link
if image_hash is not None:
link_data["image_hash"] = image_hash
if headline is not None:
link_data["name"] = headline
if description is not None:
link_data["description"] = description
if call_to_action_type is not None:
link_data["call_to_action"] = {"type": call_to_action_type}
object_story_spec: dict = {"page_id": page_id} To instead promote an existing organic post as-is, pass one of:
if video_id is not None: - object_story_id: an existing Facebook Page post, as "<page_id>_<post_id>".
video_data = {"video_id": video_id} - instagram_user_id + source_instagram_media_id: an existing Instagram post
if message is not None: (source_instagram_media_id is the IG media id); page_id must still be set
video_data["message"] = message to the Facebook Page linked to that Instagram account.
if call_to_action_type is not None: In both cases message/link/image_hash/video_id/headline/description/
video_data["call_to_action"] = {"type": call_to_action_type} call_to_action_type are ignored since the ad reuses the published post."""
object_story_spec["video_data"] = video_data if object_story_id is not None:
payload = {"name": name, "object_story_id": object_story_id}
elif source_instagram_media_id is not None:
payload = {
"name": name,
"object_id": page_id,
"instagram_user_id": instagram_user_id,
"source_instagram_media_id": source_instagram_media_id,
}
else: else:
object_story_spec["link_data"] = link_data link_data: dict = {}
if message is not None:
link_data["message"] = message
if link is not None:
link_data["link"] = link
if image_hash is not None:
link_data["image_hash"] = image_hash
if headline is not None:
link_data["name"] = headline
if description is not None:
link_data["description"] = description
if call_to_action_type is not None:
link_data["call_to_action"] = {"type": call_to_action_type}
object_story_spec: dict = {"page_id": page_id}
if video_id is not None:
video_data = {"video_id": video_id}
if message is not None:
video_data["message"] = message
if call_to_action_type is not None:
video_data["call_to_action"] = {"type": call_to_action_type}
object_story_spec["video_data"] = video_data
else:
object_story_spec["link_data"] = link_data
payload = {"name": name, "object_story_spec": object_story_spec}
payload = {"name": name, "object_story_spec": object_story_spec}
return _request("POST", f"/{_act(ad_account_id)}/adcreatives", data=_form(payload)).json() return _request("POST", f"/{_act(ad_account_id)}/adcreatives", data=_form(payload)).json()