#Problems sending images to API

1 messages · Page 1 of 1 (latest)

vague sand
#

I'm really struggling to be able to send images to the api for variations and edits. I just keep getting 1 of 2 errors. 1 'image is a required property' or I get 'image not attach or may be wrong format'. Can anyone shed any light on what I'm doing wrong.

$imagePath = "images/test.png";    
    
// Tried
// $image_data = new CURLFile($imagePath, 'image/png', 'test_name');

$data = array(
    // Tried
    //'image' => $image_data,
    'image' => '@'.$imagePath,
    'n' => $imageCount,
    'size' => $imageSize,
    'response_format' => 'url',
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: multipart/form-data',
    'Authorization: Bearer '.$api_key
));