-1

I met similar issue several times.
Below is success call

  var createAdset_params = {
    method: "post"
  }
  var url = "https://graph.facebook.com/v2.12/act_"+req.body.ADACCOUNT_ID+"/adsets?access_token="+req.body.access_token + 
    "&name=My+Reach+Ad+Set"+
    "&optimization_goal=REACH"+
    "&billing_event=IMPRESSIONS"+
    "&bid_amount=2"+
    "&daily_budget=1000"+
    "&campaign_id="+req.body.CAMPAIGN_ID+
    "&targeting=%7B%22geo_locations%22%3A%7B%22countries%22%3A%5B%22US%22%5D%7D%7D"+
    "&status=PAUSED"+
    "&promoted_object%3A%20%7B"+
    "page_id%3A%20%"+req.body.PAGE_ID+"%22%7D";
  request({url:url, qs: createAdset_params}, function(err, response, body) {
      if(err) {
        console.log(err); return; 
      }
      console.log("create adset result", body);
      res.send(body);
  });

Create ad set and return id of adset.

Below is not success call.

  var createAdset_params = {
    method: "post"
    name:"My Reach Ad Set",
    promoted_object: {page_id: req.body.PAGE_ID},
    optimization_goal: "REACH",
    billing_event:"IMPRESSIONS",
    bid_amount:2,
    daily_budget:1000,
    campaign_id:req.body.CAMPAIGN_ID,
    status: "PAUSED",
    targeting:{ 
      geo_locations: {countries:["US"]}
    }
  }
  var url = "https://graph.facebook.com/v2.12/act_"+req.body.ADACCOUNT_ID+"/adsets?access_token="+req.body.access_token;
  request({url:url, qs: createAdset_params}, function(err, response, body) {
      if(err) {
        console.log(err); return; 
      }
      console.log("create adset result", body);
      res.send(body);
  });

Showing admin permission error, even if the access_token is admin's access_token which is success with on first call.
Is there someone success with the format of below one(regular post request format)?
Any kind of hint will greatly appreciate!

artgb
  • 3,177
  • 6
  • 19
  • 36
  • Well have you at least checked what both requests eventually look like, and what the major differences are ...? – CBroe Mar 24 '18 at 10:57
  • Hi @CBroe, first is url format and second is form format, it's not just javascript related but related to facebook api, graph api explorer get same result – artgb Mar 25 '18 at 02:47
  • I still don't get what your actual question is then ...? You have one format that works, so why would you need another one? _"first is url format and second is form format"_ - well in your code maybe, but what are the actual requests that finally get made? Not so sure there is as much of a difference as you think there is - in both cases the values seem to get transported via the query string, and `post` is only passed as a GET parameter as well (to indicate the method to the API, without making it an _actual_ POST request.) – CBroe Mar 25 '18 at 08:36

1 Answers1

0

If you are checking facebook marketing api doc, to create an adset all parameters are posted as form, instead of query string.

var createAdset_params = {
    name:"My Reach Ad Set",
    promoted_object: {page_id: req.body.PAGE_ID},
    optimization_goal: "REACH",
    billing_event:"IMPRESSIONS",
    bid_amount:2,
    daily_budget:1000,
    campaign_id:req.body.CAMPAIGN_ID,
    status: "PAUSED",
    targeting:{ 
        geo_locations: {countries:["US"]}
    },
    access_token: req.body.access_token
};
var url = "https://graph.facebook.com/v2.12/act_"+req.body.ADACCOUNT_ID+"/adsets";
request({
    url : url,
    method: 'POST',
    form: createAdset_params
}, function(err, response, body) {
    if(err) {
        console.log(err); return; 
    }
    console.log("create adset result", body);
    res.send(body);
});
Ben
  • 5,069
  • 4
  • 18
  • 26
  • Hi @Ben, did you tested with above? I already tested it with graph api explorer as form, and showing "Only Admins Can Run Ads for Pages". That's why I asked this question – artgb Mar 25 '18 at 02:44
  • then you don't have enough permission to create adset, check your access token see if you have `ads_management, ads_read` scope, https://developers.facebook.com/tools/debug/accesstoken – Ben Mar 25 '18 at 06:22