Can't Create Creative Banner Via API

96 views
Skip to first unread message

Cu Rảnh

unread,
Mar 3, 2017, 9:43:50 AM3/3/17
to PocketMath API
Hi my friend!

I have a problem when i using API to Create a Creative for banner

array(8) { ["name"]=> string(7) "Cu ranh" ["type"]=> string(6) "banner" ["tld"]=> string(10) "Việt Nam" ["landing_page_url"]=> string(29) "http://go2mobi.icodedark.com/" ["image_url"]=> string(0) "" ["categories"]=> string(6) "IAB1-6" ["size"]=> string(6) "468x60" ["image_file"]=> string(72) "@/var/sentora/temp/phpdjybqw;filename=testimage468x60.png;type=image/png" } object(stdClass)#1 (1) { ["errors"]=> object(stdClass)#2 (2) { ["creative_image.image"]=> array(1) { [0]=> string(20) "Image can't be blank" } ["tld"]=> array(2) { [0]=> string(14) "TLD is invalid" [1]=> string(14) "TLD is invalid" } } }

Image can't be blank

I don't know why. http://go2mobi.icodedark.com/ my test site.

Can you help me how i can do it. 

My code :

$post = array(
'image' => '@' . $_FILES['image']['tmp_name']
        . ';filename=' . $_FILES['image']['name']
          . ';type='     . $_FILES['image']['type']
);

// $post['creative']['image'] = '@' . $_FILES['image_file']['tmp_name'];

var_dump($post);


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type : multipart/form-data','Accept: application/json','Authorization: Token 8994c89545974a8a703708efa5364d8654f7cc8638dba3d221707a8dcf61415c'));
// curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type : application/json','Authorization: Token 8994c89545974a8a703708efa5364d8654f7cc8638dba3d221707a8dcf61415c'));
curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_UPLOAD, 1);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$result = curl_exec($ch);

var_dump( $result);

curl_close($ch); 

Thank a lot!
Thanh N.

Andi Susanto

unread,
Mar 9, 2017, 10:45:13 PM3/9/17
to PocketMath API
Hello Thanh,

Can you try uploading the image using Postman? This is the cURL code that is working for me:

curl -X POST -H "Authorization: Token token=***" -H "Cache-Control: no-cache" -H "Postman-Token: ***" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F "image_file=@Screen Shot 2017-03-03 at 1.38.04 PM.png" -F "type=banner" -F "size=468x60" -F "categories=IAB1-6" -F "landing_page_url=http://go2mobi.icodedark.com" -F "name=Cu ranh 2" -F "tld=icodedark.com" "https://api.pocketmath.com/v2/creatives"

Then you can simply replicate this code in your controller.

Cheers!
Andi
Reply all
Reply to author
Forward
0 new messages