UploadListingImage endpoint "image" parameter unclear.

103 views
Skip to first unread message

Craig Williams

unread,
Sep 14, 2021, 2:05:24 PM9/14/21
to Etsy API
Hi, I am having trouble understanding what is required in the "image" parameter when uploading an image to a listing. When I try to add binary data I get the following response content:

{"error":"Either a valid image file or a listing_image_id must be provided."}

I am uncertain exactly what is required; I have tried converting a binary byte array to a base64 string which had the same result. Is there a particular encoding required? 

To further cloud the issue the API reference states that the "image" parameter accepts: 'string <binary>The file name string of a file to upload'. However, the app is for duplication of listings from Shopify so I grab the image byte array from a URL.

The documentation isn't clear and unfortunately the development team haven't responded to me regarding this issue.

Any light shed on this would be greatly appreciated.

Thanks,

Craig 

Samuel

unread,
Sep 20, 2021, 8:51:25 AM9/20/21
to Etsy API
There's some server-side parameter that's extremely finicky, although I haven't identified specifically which one it is. I've wasted a bunch of time with syntactially-correct file upload POSTs that were rejected by the server.

Delvng through the bug reports on github led me to find a solution that works. Here's Nate Sanden's PHP code that I've used successfully:

$curl = curl_init();

//path to the image you want to upload
//can be local path or remote url
$image_url = dirname(__FILE__).'/thumb.jpg';

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => [
       'image' => new CURLFile($image_url),
       'name' => basename($image_url),
    ],
    CURLOPT_HTTPHEADER => array(
        'Content-Type: multipart/form-data',
        'x-api-key: '.$client_id,
        'Authorization: Bearer '.$access_token,
    ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Jan Masar

unread,
Sep 22, 2021, 3:59:43 PM9/22/21
to Etsy API
Hi
Are you using python? I have the same problem {'error': 'Either a valid image file or a listing_image_id must be provided.'} and I cant figure this out. 
I ask the question here in this group, it wasn't posted  (I tried twice). 
Please let me know if you have a solution.

Thanx

joey...@gmail.com

unread,
Nov 5, 2021, 8:28:02 AM11/5/21
to Etsy API
Thank you! This was a very helpful response. I was having the same problem, but your answer resolved it. I appreciate that you took the time to provide this.
Reply all
Reply to author
Forward
0 new messages