Posts tagged with facebook-marketing-api

I am currently using facebook-nodejs-business-sdk:"^18.0.0" graph api for Insights.

I have below piece of code in map which returns array of Api requests. Using the the instance of FacebookAdsApiBatch i am putting each request into it which should return multiple results as it batch

return new APIRequest(    `http://graph.facebook.com/v18.0/${levelId}`    'GET',    'insights' )  .addParam('access_token', XX_X_X)  .addParam('fields', 'impression, clicks')  .addParam('level', levelType) 

Above Array of APIRequest passed in below fucntion

async getBatchRequestResult(requests: APIRequest[]): Promise<any> {   const batchApi = new FacebookAdsApiBatch(      getFbApiInstance(),      (res) =>{         console.log('batch instance success ', res)      },      (error) => {         console.log('batch instance error', error)      }   )   reqests.forEach((request) => {      batchApi.addRequest(         request,          (data) => {           console.log(' Success addRequest: ${JSON.stringify(data)}')          },         (error) => {           console.log('error', error)         }      )   })   return new Promise((resolve, reject) => {       batchApi         .execute()         .then((responses) => {            console.log('***RESPONSES****', responses);            resolve(responses)         })         .catch((error) => {            console.log('***ERROR****', error);            reject(error)         })         }) } 

Current in lambda logs I am seeing 3 types of logs in order.

  1. batch instance success: { kind of same json as below }
  2. Muliple "Success addRequest" logs. One of mentioned below Success addRequest:
{  "_body": {     "https://graph.facebook.com/v18.0/<CAMPAIGN_ID>/insights"   }  "status": 200,  "_headers": [     long list of objects   ],  "_call": {     "method": "GET",     "relative_url": "https://graph.facebook.com/v18.0/<CAMPAIGN_ID>/insights?                         access_token=XX_X_X                        &**fields**=&level=campaign"     "attachedFiles": ""      }     .......     .......   } } 
  1. RESPONSES = Null

Question is, If we pay attention on relative_url the fields value is empty despite the fact I am passing string 'impression, clicks'. I tried with array ["impression", "clicks"] and addParams({ key:Val }) but it still not passing that value. Really not sure why it is ommitting. All other parameters are fine. I doubt that this is the why I am facing issue of Null as final result. fields is important for me because I have to fetch tons of other measures as well.

Can someone please help me to figure out what is the issue? If anyone need further detail I am ready to give as much I can.

Currently in codebase we have "new Campaign" instance which has getInsights(null, query) fun which working fine. I am replacing this and trying batch call to avoid timeout error from FB for all kind of insights (campaign, adsets, ad) and therir breakdowns and mesures. By achiveing above batch call, the number of API calling to FB would be significantly reduced.

Reference: https://www.npmjs.com/package/facebook-nodejs-business-sdk?activeTab=code ^ Go under BatchExample.js

I'm trying to change a campaign status using the Facebook Marketing API as documented here.

I managed to change the campaign status to PAUSED, but I can't change it back to ACTIVE, even though the API response indicates success.

Here is the API request I'm making:

https://graph.facebook.com/v19.0/{campaign_id}?access_token={token}&status=ACTIVE

The response I get is:

{   "success": true } 

However, the campaign status remains paused. Has anyone encountered this issue or know why the status isn't updating despite the success response?

Additional details:

  • I used the same approach to pause the campaign, and it worked perfectly.

  • The access token and campaign ID are correct.

Any help would be greatly appreciated!

I am trying to change the status of a Facebook campaign using their Marketing API as documented here. However, I keep encountering the following error:

{     "error": {         "message": "Unknown path components: /<campaignId>",         "type": "OAuthException",         "code": 2500,         "fbtrace_id": "AZruauHBbtO4IzLuRmF90c-"     } } 

Here is the full API request I'm making:

https://graph.facebook.com/v19.0/act_<accountId>/campaigns/<campaignId>?access_token=<token>&status=PAUSED 

I've tried double-checking my IDs and access token, and they are correct.

Can anyone help me understand what might be going wrong and how to fix this error?

What I've tried:

  • Verifying that the campaign ID and access token are correct.

  • Checking if the endpoint and parameters are correctly formatted.

I want to create an ad creative with the Meta/Facebook Marketing API. The goal is to create an ad creative which I can turn into an ad which has multiple images and primary texts and titles.

As shown in the picture, I want to have the same image in "Feeds, In-Stream Ads for Videos and Reels, Search Results" and "Right Hand, Search Results". I want a different image in "Stories and Reels, Apps and Websites".

Additionally, I want to specify multiple primary texts and multiple titles.

I tried to create the creative using this:

{     "object_story_spec": {       "page_id": "PAGE_ID"     },     "asset_feed_spec": {       "images": [         {           "hash": "HASH1",           "adlabels": [{"name": "label_feed"}]         },         {           "hash": "HASH2",           "adlabels": [{"name": "label_story"}]         }       ],       "bodies": [         {           "text": "Begin Your Adventure"         }       ],       "titles": [         {           "text": "Level Up"         },         {           "text": "Level Up 2"         }       ],       "call_to_action_types": [         "SHOP_NOW"       ],       "link_urls": [         {           "website_url": "https://www.example.com/"         }       ],       "ad_formats": [         "SINGLE_IMAGE"       ],       "asset_customization_rules": [         {           "customization_spec": {             "publisher_platforms": [               "facebook"             ],             "facebook_positions": [               "feed"             ]           },           "image_label": {             "name": "label_feed"           }         },         {           "customization_spec": {             "publisher_platforms": [               "instagram"             ],             "instagram_positions": [               "story"             ]           },           "image_label": {             "name": "label_story"           }         }       ]       },   "status": "PAUSED",   "degrees_of_freedom_spec": {         "creative_features_spec": {             "standard_enhancements": {                 "enroll_status": "OPT_OUT"             }         }     } } 

However, it gives me an error:

Multiple title elements cannot be applied to rule #1 (Priority, if specified, or index of the rule) in the Ad Asset Feed.

Additionally, it seems like I have to specify adlabels in the asset story spec. How can I place the images in the categories without the adlabels?

I have two function. One is responsible for creating audience for the engaged page of Facebook and the other is for creating a custom audience for Instagram business account. I am using step functions to call my lambdas function. But whenever I try to create audience of Facebook and Instagram simultaneously, so I received an error of permission

No permission on event source: You do not have permission to create an audience on one or more event sources

But when I try to create a single audience for example just only for Facebook or just only for Instagram there is no error for the permissions but when I try to create audience simultaneously for the Facebook and for the Instagram business account I got this error

const createSocialAudience = async ({     name,     pageId,     adsAccountId,   } ) => {     if (!name || !adsAccountId || !pageId) {       throw new Error('Marketing API call missing required params');     }     const requestData = {       name,       description: 'Recent page visitors (from 360 days) visiting given page',       rule: {         inclusions: {           operator: 'or',           rules: [             {               event_sources: [                 {                   type: "page",                   id: pageId,                 },               ],               retention_seconds: 60* 60* 24 * 360,               filter: {                 operator: 'and',                 filters: [                   {                     field: 'event',                     operator: 'eq',                     value: 'page_engaged',                   },                 ],               },             },           ],         },       },       access_token: params.marketingApiToken,     };     const { data } = await httpClient.post(       `https://graph.facebook.com/v19.0/act_${adsAccountId}/customaudiences`,       JSON.stringify(requestData)     );     return data;   };   const createInstagramAudience = async ({     name,     igUserId,     adsAccountId,   })  => {     if (!name || !adsAccountId || !igUserId) {       throw new Error('Marketing API call missing required params');     }     const requestData = {       name,       description: 'Recent page visitors (from 360 days) visiting given page',       rule: {         inclusions: {           operator: 'or',           rules: [             {               event_sources: [                 {                   type: 'ig_business',                   id: igUserId,                 },               ],               retention_seconds: 60 *60 * 24 * 360,               filter: {                 operator: 'and',                 filters: [                   {                     field: 'event',                     operator: 'eq',                     value: 'ig_business_profile_engaged',                   },                 ],               },             },           ],         },       },       access_token: params.marketingApiToken,     };     const { data } = await httpClient.post(       `https://graph.facebook.com/v19.0/act_${adsAccountId}/customaudiences`,       JSON.stringify(requestData)     );     return data;   }; 

Expecting to create both of my audience at the same time for example I want two type of event_sources one for page of Facebook and one for ig_business