2

My goal is to create a number of ads using Facebook's Batch API : https://developers.facebook.com/docs/marketing-api/asyncrequests/v2.9

I am sending a POST request at this URL:

https://graph.facebook.com/v2.9/act_158365238/ads

I am sending 2 parameters as per the documentation:

1- access_token

2- batch

The JSON in the batch parameter looks like :

{
  "method": "POST",
  "relative_url": "v2.9\/act_158365238\/ads",
  "attached_files": "test1",
  "body": "creative={\"title\":\"Test title 1\",\"body\":\"Test body 1\",\"object_url\":\"https:\/\/apps.facebook.com\/testapp\/\", \"image_file\":\"test1.jpg\"}&targeting={\"countries\":[\"US\"]}&name=test1"
}

The Problem

When I send this request with POSTman or my PHP code, it throws the following error

{
  "error": {
    "message": "(#100) The parameter creative is required",
    "type": "OAuthException",
    "code": 100,
    "fbtrace_id": "Gj2sG7N8l1f"
  }
}

However when I send the exact same request via Facebook's Graph API tool, it successfully creates the ads.

Zahid Sattar
  • 1,467
  • 2
  • 13
  • 21

2 Answers2

1

According to the API Documentation provided to create creatives you should be posting to the URL "v2.9/act_187687683/adcreatives"... The fragment of the batch that you are showing is used to create an Ad.

If, as you say, your intention is to create an AdCreative then you should be using something like the above, which differs in the body from what you are using:

         {
          "method": "POST",
          "name": "create_creative",
          "relative_url": "v2.9/act_187687683/adcreatives",
          "attached_files": "test1",
          "body": "title=Test title&body=Test body&link_url=http://www.test12345.com&image_file=test1.jpg"
         }

In the other hand, if what you are creating is an add, then you should consider referencing the AdCreative by its ID as is done in the examples, hence in the case of a creative added in the same batch you could use the relative reference to the name:

         creative={\"creative_id\":\"{result=create_creative:$.id}\"}

or if it is a creative already created you can reference it by the creative_id:

         creative={\"creative_id\":\"123456\"}
xtoik
  • 676
  • 5
  • 11
  • I miswrote. I need to create ads not ad creatives. Let me edit that. I have already tried referencing the ad creative by it's ID. In my question you will see me attempting to create an ad by passing in the whole creative credentials. In either case the error that I am facing is the same (please see above) – Zahid Sattar May 30 '17 at 15:44
0

I think the message is a red herring -- it's not seeing your body's creative field because the OAuth isn't properly set in your POSTman requests, so it isn't parsing the body or seeing the creative field.

If you don't know how to set OAuth in POSTman, here's a good tutorial: https://docs.brightcove.com/en/video-cloud/concepts/postman/postman.html

Aidan Hoolachan
  • 2,285
  • 1
  • 11
  • 14
  • You are right on @ "it's not seeing your body's creative field". POSTman doesn't see it no matter what I do. My PHP code also returns the same error. An ad is created however, if I use the exact same JSON in the graph explorer. – Zahid Sattar Jun 05 '17 at 07:35