Error Image file or image_id string must be included

1,107 views
Skip to first unread message

Joseph Brown

unread,
Aug 17, 2014, 4:37:30 PM8/17/14
to etsy-...@googlegroups.com
I'm sorry I feel like I'm starting to take over this forum.
I am trying to upload a image and I'm getting the error Image file or image_id string must be included. I'm including the raw request and the returned headers. Perhaps someone can spot something I'm doing incorrectly here. Or maybe Etsy API can shed some light on what they are actually receiving.

Thanks in advance.

Request
Accept: */*
Accept-Language: en
Content-length: 20878
Authorization: OAuth oauth_consumer_key="[key]",oauth_signature_method="HMAC-SHA1",oauth_nonce="qwb1dgvco0bd35rop2q2kb3qalmfg9cj",oauth_timestamp="1408306744",oauth_version="1.0",oauth_token="[token]",oauth_signature="%2qGLDILhWmrwKpZG7YwkeX49TXoY%3D"
Connection: Keep-Alive
Pragma: no-cache
Content-Type: multipart/form-data; boundary=fc684a0c-ac89-4771-9ca0-61d0a4326b65
--fc684a0c-ac89-4771-9ca0-61d0a4326b65
Content-Disposition: form-data; name="userfile"
Poly1.jpg
--fc684a0c-ac89-4771-9ca0-61d0a4326b65
Content-Disposition: form-data; name="image"; filename="Poly1.jpg"
Content-Type: image/jpeg
Content-Length: 20544
Content-Transfer-Encoding: binary

[raw data]
--fc684a0c-ac89-4771-9ca0-61d0a4326b65--

Returned Headers
HTTP/1.1 400 Bad Request
Date: Sun, 17 Aug 2014 20:19:13 GMT
Server: Apache
X-Etsy-Request-Uuid: MR8IvCBibWa0biiuB1YXSxh8bdRr
X-RateLimit-Limit: 10000
X-RateLimit-Remaining: 9984
X-Error-Detail: Image file or image_id string must be included
Cache-Control: private
X-Cnection: close
Content-Type: text/plain;charset=UTF-8
Content-Length: 46
Accept-Ranges: bytes
Via: 1.1 varnish
X-Served-By: cache-sjc3126-SJC
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1408306753.529277086,VS0,VE208
Vary: Accept-Encoding
Set-Cookie: uaid=uaid%3Db1ylwJtYwVIOjnlvd1oYF3zHivLt%26_now%3D1408306753%26_slt%3DBqs0S_Ia%26_kid%3D1%26_ver%3D1%26_mac%3DLi85jnz6IXyrP0Awm6bir6bUNTUPEST6gaLoU4eztoI.; expires=Tue, 16-Aug-2016 20:19:13 GMT; path=/; domain=.etsy.com; httponly
Connection: close


Joseph Brown

unread,
Aug 18, 2014, 11:22:48 AM8/18/14
to etsy-...@googlegroups.com
Although the goal is not to use the php implementation I'm posting a test I did with it where I'm getting the same results. Maybe useful maybe not one can only hope.
<?php

$consumer_key = '[masked]';
$consumer_secret = '[masked]';
$access_token = '[masked]';
$access_token_secret = '[masked]';

$oauth = new OAuth( $consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);

$oauth->setNonce ( 'random' );
$oauth->enableDebug();
$oauth->setRequestEngine( OAUTH_REQENGINE_CURL );
$oauth->setToken($access_token, $access_token_secret);

$source_file = dirname(realpath(__FILE__)) ."/Poly1.jpg";

if ( file_exists( $source_file ) ) {

try {
$parameterss = array('@image' => '@'.$source_file.';type=image/jpeg');
$data = $oauth->fetch( $url, $parameters, OAUTH_HTTP_METHOD_POST);
$json = $oauth->getLastResponse();
print_r(json_decode($json, true));
} catch (OAuthException $e) {
print_r($oauth->debugInfo);
exit;
}
} else {
echo 'image not found';
}

?>


Returned from php request
Array
(
    [sbs] => POST&https%3A%2F%2Fopenapi.etsy.com%2Fv2%2Flistings%2F200094932%2Fimages&oauth_consumer_key%3D[masked]%26oauth_nonce%3Drandom%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1408374616%26oauth_token%3D[masked]%26oauth_version%3D1.0
    [headers_sent] => POST /v2/listings/200094932/images?oauth_consumer_key=[masked]&oauth_signature_method=HMAC-SHA1&oauth_nonce=random&oauth_timestamp=1408374616&oauth_version=1.0&oauth_token=[masked]&oauth_signature=M0FBGvMgNOuhb1r3Ln9NaQIIFSM%3D HTTP/1.1
User-Agent: PECL-OAuth/1.2.3
Accept: */*
    [headers_recv] => HTTP/1.1 400 Bad Request
Date: Mon, 18 Aug 2014 15:10:07 GMT
Server: Apache
X-Etsy-Request-Uuid: F2Y9eBN91GSEB7EIPzCKLAHHkyyi
X-RateLimit-Limit: 10000
X-RateLimit-Remaining: 9994
X-Error-Detail: Image file or image_id string must be included
Cache-Control: private
X-Cnection: close
Content-Type: text/plain;charset=UTF-8
Content-Length: 46
Accept-Ranges: bytes
Via: 1.1 varnish
X-Served-By: cache-dfw1829-DFW
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1408374607.161081314,VS0,VE206
Vary: Accept-Encoding
Set-Cookie: uaid=uaid%3DA7gICSophLGrhclExqJAiz-AQzJj%26_now%3D1408374607%26_slt%3DHkL30WQH%26_kid%3D1%26_ver%3D1%26_mac%3DYxX5sA_Ji6melhnPha0ZPlEpQAOraibX85ziR3EgU1U.; expires=Wed, 17-Aug-2016 15:10:07 GMT; path=/; domain=.etsy.com; httponly
Connection: close
    [body_recv] => Image file or image_id string must be included
    [info] => About to connect() to openapi.etsy.com port 443 (#0)
  Trying 23.235.44.185... connected
successfully set certificate verify locations:
  CAfile: none
  CApath: /etc/ssl/certs
SSLv3, TLS handshake, Client hello (1):
SSLv3, TLS handshake, Server hello (2):
SSLv3, TLS handshake, CERT (11):
SSLv3, TLS handshake, Server key exchange (12):
SSLv3, TLS handshake, Server finished (14):
SSLv3, TLS handshake, Client key exchange (16):
SSLv3, TLS change cipher, Client hello (1):
SSLv3, TLS handshake, Finished (20):
SSLv3, TLS change cipher, Client hello (1):
SSLv3, TLS handshake, Finished (20):
SSL connection using ECDHE-RSA-RC4-SHA
Server certificate:
subject: C=US; ST=California; L=San Francisco; O=Fastly, Inc.; CN=*.a.ssl.fastly.net
start date: 2014-01-01 00:00:00 GMT
expire date: 2015-01-05 12:00:00 GMT
subjectAltName: openapi.etsy.com matched
issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Assurance CA-3
SSL certificate verify ok.
Closing connection #0
SSLv3, TLS alert, Client hello (1):
)

david olick

unread,
Aug 18, 2014, 3:40:16 PM8/18/14
to Etsy API V2
You have to upload a "multipart/form-data" where the message + body of the post looks like this:

Content-Length: 269
Content-Type: multipart/form-data; boundary=xYzZY

--xYzZY

Content-Disposition: form-data; name="image"; filename="fotofuze.jpg"

Content-Type: image/jpeg

[76887 random characters]

--xYzZY

Content-Disposition: form-data; name="rank"

1

--xYzZY

Content-Disposition: form-data; name="overwrite"

1

--xYzZY--


Notice how the message has a Content-Type (multipart/form-data) and the image has it's own Content-Type (image/jpeg).  My spacing might be a little off, but this should get you in the right direction.



--
David Olick
Oriku Inc.


--
You received this message because you are subscribed to the Google Groups "Etsy API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to etsy-api-v2...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joseph Brown

unread,
Aug 18, 2014, 10:16:30 PM8/18/14
to etsy-...@googlegroups.com, david...@gmail.com
Thank You!!! I works like a charm now :)

Hyyudu

unread,
Apr 29, 2016, 11:37:26 AM4/29/16
to Etsy API, david...@gmail.com
I'm trying to upload image via PHP OAuth

$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->setToken($access_token, $access_token_secret);
$url
=
"https://openapi.etsy.com/v2/listings/277895742/images";
$data = array('image' =>'@folder/pixel.jpg'); // also tried to provide full path from /wwwroot
$headers = array("Content-Type" => "multipart/form-data"); // also tried to add Content-Length
$oauth
->fetch($url, $data, OAUTH_HTTP_METHOD_POST, $headers);

With this I got an error:
Invalid auth/bad request (got a 400, expected HTTP/1.1 20X or a redirect)
with message in debug info: "the request body is too large".
Where can the problem be? Image is 1x1 pixel, I also tried 250x250. Maybe I shouldn't use $oauth and pass raw image data via sockets or file_get_contents with stream_context?

Thanks in advance.

понедельник, 18 августа 2014 г., 22:40:16 UTC+3 пользователь david olick написал:

Jorge Rodríguez Trías

unread,
May 24, 2016, 10:23:39 AM5/24/16
to Etsy API
this is my workaround:

First install PECL Oauth 1.2.3 in Ubuntu:

sudo pecl install oauth-1.2.3


edit php.ini:

sudo nano /etc/php5/apache2/php.ini


add next line:

extension=oauth.so NOT at final of php.ini


restart service:

sudo /etc/init.d/apache2 restart 



The code


 

try 
{
//initialize oauth
$oauth2 = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth2->setRequestEngine( OAUTH_REQENGINE_CURL );
$oauth2->setVersion("1.1"); //very important
$oauth2->enableDebug();
$oauth2->setToken($access_token, $access_token_secret);
    //params
$listing_id = '4564613216'; //id of a listing/product
$url = "https://openapi.etsy.com/v2/listings/".$listing_id."/images";
$filename = "image.jpg";
$source_file = dirname(realpath(__FILE__)) ."/images/$filename";
$mimetype = mime_content_type($source_file);
$filesize = filesize($source_file);
$params = array('@image' => '@'.$source_file.';type='.$mimetype); 
//buid some header params
$header["Content-Type"] = 'multipart/form-data';
$header["Content-Length"] = $filesize;
$header["Content-Disposition"] = 'form-data; name="image"; filename="image.jpg"';
$header["Content-Transfer-Encoding"] = 'binary';
//execute 
$data = $oauth2->fetch($url, $params, OAUTH_HTTP_METHOD_POST, $header);
$json = $oauth2->getLastResponse();
    print_r(json_decode($json, true));
catch (OAuthException $e) 
{
    // You may want to recover gracefully here...
    print $oauth2->getLastResponse()."\n";
    print_r($oauth2->debugInfo);
    die($e->getMessage());
}





$oauth2 = new OAuth(OAUTH_CONSUMER_KEYOAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth2->setRequestEngine( OAUTH_REQENGINE_CURL );
$oauth2->setVersion("1.1");
$oauth2->enableDebug();
$oauth2->setToken($db->f('access_token'), $db->f('access_token_secret'));
$url = "https://openapi.etsy.com/v2/listings/".$listing_id."/images";
$filename = "wall.jpg";
$source_file = dirname(realpath(__FILE__)) ."/images/$filename";
$mimetype = mime_content_type($source_file);
$filesize = filesize($source_file);
$params = array('@image' => '@'.$source_file.';type='.$mimetype); 
$header["Content-Type"] = 'multipart/form-data';
$header["Content-Length"] = $filesize;
$header["Content-Disposition"] = 'form-data; name="image"; filename="wall.jpg"';
$header["Content-Transfer-Encoding"] = 'binary';
$data = $oauth2->fetch($url, $params, OAUTH_HTTP_METHOD_POST, $header);
$json = $oauth2->getLastResponse();

gauravs...@gmail.com

unread,
Nov 7, 2017, 2:27:10 PM11/7/17
to Etsy API
Hi all,
I am implementing Etsy Api in nodejs.
an any on suggest me how to implement it in JS as I am getting this error 
error:

Enter code here...<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>\nAn error occurred while processing your request.<p>\nReference&#32;&#35;95&#46;5a87d317&#46;1509978985&#46;162f55f0\n</BODY></HTML>\n

here is my code:
Enter code here...
var oauth = {
  consumer_key: key,
  consumer_secret: secret,
  token: token,
  token_secret: tokenSecret,
  version: 1.1
};
request({
    method: 'POST',
    preambleCRLF: true,
    postambleCRLF: true,
    oauth:oauth,
    json: true,
    headers:{
      'Content-Type': 'multipart/form-data',
      'Content-length': 2000,
      'Content-Disposition': 'form-data; name="image"; filename="canvas.png"',
      'Content-Transfer-Encoding': 'binary',
      'accept':'image/webp,image/apng,image/*,*/*;q=0.8'
    },
    uri: `https://openapi.etsy.com/v2/listings/${
listingId}
/images`,
    body: {
      'image': fs.createReadStream(__dirname+'/'+'canvas.png' ),
      "rank": 1,
      'listing_id': listingId

    }
  },
  function (error, response, body) {
    if (error) {
      return console.error('upload failed:', error);
    }
    console.log(response,body);
  })

Thanks in advance

Jeetu

unread,
Apr 26, 2021, 3:02:48 PM4/26/21
to Etsy API
Thanks - this put me on the right track. Above code worked - but I had to install libcurl4-gnutls-dev and  libpcre3-dev  before installing oauth using pecl.  This was needed to make OAUTH_REQENGINE_CURL work (and without this setting, image upload failed).
Notice of confidentiality: This communication may contain confidential or privileged information.
Unauthorised review, use, disclosure or sharing of the contents of this communication is prohibited.
If it was not intended for you, please delete the message and notify the sender immediately.
Reply all
Reply to author
Forward
0 new messages