imageuploadinternal-server-erroretsy

Etsy Image add returning 500 error - metadata doesn't look like a _FILES array


I am trying to add an images to an existing Etsy listing. Should be simple right? But I'm following the API code here: https://www.etsy.com/developers/documentation/reference/listingimage

And am getting an internal server 500 error response: ""The image array metadata doesn't look like a _FILES array""

I have no idea what this error means. Anyone?

Here is my code:

<?php
$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);

$oauth->enableDebug();
$oauth->setToken($access_token, $access_token_secret);
$listing_id = 245891757
$filename = 161784082898-0.JPG;
$mimetype="image/jpeg";


try {
    $source_file = dirname(realpath(__FILE__)) ."/$filename";
    $url = "https://openapi.etsy.com/v2/listings/".$listing_id."/images";
    $params = array('image' => '@'.$source_file.';type='.$mimetype);

    $oauth->fetch($url, $params, OAUTH_HTTP_METHOD_POST);

    $json = $oauth->getLastResponse();
    print_r(json_decode($json, true));

} catch (OAuthException $e) {
    // You may want to recover gracefully here...
    print "<br><br>".$oauth->getLastResponse()."\n";
    print_r($oauth->debugInfo);
    die($e->getMessage());
}
?>

Solution

  • Solved.

    code added: $oauth->setRequestEngine( OAUTH_REQENGINE_CURL );

    If the above fails with an error - re-install the PHP PECL extension and add Curl as a "Request Engine".