Search code examples
node.jsfacebook-ads-apifacebook-marketing-api

How to update an Adsets (nested) targeting options via the Facebook Marketing API?


I'm trying to update an existing Adsets targeting options, but I just want the publisher_platforms to be changed. The error message I get is the following:

  error_user_msg: 'Your audience is missing a location. You can add a location or a Custom Audience.',

This error shows me that I'm using the wrong endpoint, since I just want update one targeting field not the entire options.

Here is my call to the api

const options = {
    method: "POST",
    uri: `https://graph.facebook.com/v4.0/${adSetId}`,
    qs: {
      access_token: accessToken,
      "targeting": {publisher_platforms: ["instagram"]}
    }
};

request(options, (err, data, body) => {

   console.log("updateFacebookCampaign", "then..." ,{
     body
   });
})

Any idea how I can archive this? (incrementally updating the targeting options and not all at once)


Solution

  • You can't update a single value of the targeting field the way you are attempting to.

    When updating the adset targeting you need to pass the entire targeting object, of which geo_locations is a required field. The targeting field will be replaced by the new object you send in the update.

    To successfully update the targeting, pass the new targeting object as it would be with your updated publisher_platforms.