Im trying to create an ad on facebook using the python sdk i have created my campaigns, adset and creatives but when im trying to schedule my ad im getting this error:

facebook_business.exceptions.FacebookRequestError: 

  Message: Call was not successful
  Method:  POST
  Path:    https://graph.facebook.com/v19.0/act_3958412xxxx/ads
  Params:  {'name': 'creative_ad', 'adset_id': '1202063535xxxxx', 'creative': '{"creative_id":"12020633xxxxx"}', 'status': 'PAUSED'}

  Status:  400
  Response:
    {
      "error": {
        "message": "Invalid parameter",
        "type": "OAuthException",
        "code": 100,
        "error_subcode": 1487888,
        "is_transient": false,
        "error_user_title": "Tracking pixel required",
        "error_user_msg": "A tracking pixel is required for ads in a campaign with conversions as its objective.",
        "fbtrace_id": "AgCAXDAy3Z2IA_xxxx"
      }
    }

this is my code:

def schedule_ad(ad_account_id, adset_id, creative_id, access_token, title):
    initialize_facebook_api(app_id, app_secret, access_token)
    account = AdAccount(ad_account_id)
    fields = []
    params = {
        'name': title + '_ad',
        'adset_id': adset_id,
        'creative': {'creative_id': creative_id},
        'status': 'PAUSED',
    }
    return account.create_ad(fields=fields, params=params)

There is no documentation on facebook regarding this issue

1

There are 1 best solutions below

0
maltego2024 On

Log in to your Facebook Ads Manager account and navigate to the Pixels section. Create a new pixel if you haven't already done so.Then go to the ad campaign settings and look for the conversion tracking section and select the tracking pixel you've created.

After that you need to modify your code to include the tracking pixel when creating the ad. Add the tracking_specs parameter to your ad creation request.

def schedule_ad(ad_account_id, adset_id, creative_id, access_token, title, tracking_pixel_id):
    initialize_facebook_api(app_id, app_secret, access_token)
    account = AdAccount(ad_account_id)
    fields = []
    params = {
        'name': title + '_ad',
        'adset_id': adset_id,
        'creative': {'creative_id': creative_id},
        'status': 'PAUSED',
        'tracking_specs': [{'action.type': 'offsite_conversion', 'offsite_pixel': [{'pixel_id': tracking_pixel_id}]}]
    }
    return account.create_ad(fields=fields, params=params)