@@ -242,7 +242,7 @@ async def get_creative_details(creative_id: str, access_token: Optional[str] = N
242242 # "(#100) Tried accessing nonexisting field" on simple creatives in API v24.
243243 # We fetch the safe fields first, then try dynamic_creative_spec separately.
244244 params = {
245- "fields" : "id,name,status,thumbnail_url,image_url,image_hash,object_story_spec,asset_feed_spec,url_tags,link_url"
245+ "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"
246246 }
247247 data = await make_api_request (endpoint , access_token , params )
248248
@@ -1256,22 +1256,36 @@ async def create_ad_creative(
12561256
12571257 creative_data ["asset_feed_spec" ] = asset_feed_spec
12581258
1259- # For dynamic/FLEX creatives with asset_feed_spec, object_story_spec needs
1260- # page_id. For non-video, the link URL is already in asset_feed_spec.link_urls
1261- # so link_data is NOT added here (Meta rejects link_data without image_hash).
1259+ # For asset_feed_spec creatives, object_story_spec needs page_id
1260+ # plus a link anchor. Meta rejects bare page_id (error 2061015).
12621261 if is_video :
1263- # video_data does NOT support "link" directly — URL goes in
1264- # call_to_action.value.link or is handled by asset_feed_spec.link_urls.
1262+ # Video FLEX: use video_data with call_to_action carrying
1263+ # the link URL. This is required for Meta to associate the
1264+ # video and destination URL with the creative.
12651265 video_anchor = {"video_id" : video_id }
12661266 if thumbnail_url :
12671267 video_anchor ["image_url" ] = thumbnail_url
1268+ cta_type = call_to_action_type or "LEARN_MORE"
1269+ cta_value = {}
1270+ if link_url :
1271+ cta_value ["link" ] = link_url
1272+ if lead_gen_form_id :
1273+ cta_value ["lead_gen_form_id" ] = lead_gen_form_id
1274+ cta_data = {"type" : cta_type }
1275+ if cta_value :
1276+ cta_data ["value" ] = cta_value
1277+ video_anchor ["call_to_action" ] = cta_data
12681278 creative_data ["object_story_spec" ] = {
12691279 "page_id" : page_id ,
12701280 "video_data" : video_anchor
12711281 }
12721282 else :
1283+ # Image FLEX: use link_data with the destination URL.
12731284 creative_data ["object_story_spec" ] = {
1274- "page_id" : page_id
1285+ "page_id" : page_id ,
1286+ "link_data" : {
1287+ "link" : link_url
1288+ }
12751289 }
12761290 else :
12771291 if is_video :
@@ -1391,7 +1405,7 @@ async def create_ad_creative(
13911405 creative_id = data ["id" ]
13921406 creative_endpoint = f"{ creative_id } "
13931407 creative_params = {
1394- "fields" : "id,name,status,thumbnail_url,image_url,image_hash,object_story_spec,asset_feed_spec,url_tags,link_url"
1408+ "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"
13951409 }
13961410
13971411 creative_details = await make_api_request (creative_endpoint , access_token , creative_params )
0 commit comments