3

I am trying to create a new listing on Etsy.

  1. I used oauth to authenticate and got OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET

  2. I check it with this code and I got return og all the seller data, so everything is ok with the OAuth.

    $oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
    $oauth->setToken("key","secret"); 
    
    try {
     $data = $oauth->fetch("http://openapi.etsy.com/v2/users/__SELF__", null, OAUTH_HTTP_METHOD_GET);
     $json = $oauth->getLastResponse();
     print_r(json_decode($json, true));
    
    } catch (OAuthException $e) {
     error_log($e->getMessage());
     error_log(print_r($oauth->getLastResponse(), true));
     error_log(print_r($oauth->getLastResponseInfo(), true));
     exit;
    }
    
  3. I am trying to crate a new listings. First i managed to create a new listing through the api browser on the production. Now, i want to create a new listing through PHP. This is what i did, and it return my error:

This is my code:

$oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET,OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);

$oauth->setToken("key","secret");

try {
 $url = "http://openapi.etsy.com/v2/listings";

 $params = array('description' => 'thisisdesc','materials' => 'yes','price'=>"5.99"
 ,'quantity'=>"2",'shipping_template_id'=>"52299",'shop_section_id'=>"1"
 ,'title'=>"thisistitle",'category_id'=>"i_did",'who_made'=>"5.99"
 ,'is_supply'=>"1",'when_made'=>"2010_2012");


 $oauth->fetch($url, $params, OAUTH_HTTP_METHOD_POST);
 print_r(json_decode($json, true));

} catch (OAuthException $e) {

 print_r($e);

 error_log($e->getMessage());
 error_log(print_r($oauth->getLastResponse(), true));
 error_log(print_r($oauth->getLastResponseInfo(), true));
 exit;
}

I get the response of:

Invalid auth/bad request (got a 403, expected HTTP/1.1 20X or a redirect) 
This method not accessible to restricted API key. 
user229044
  • 232,980
  • 40
  • 330
  • 338
Yan
  • 1,424
  • 4
  • 21
  • 44
  • Hmm, do a web search on "Etsy restricted API key". I wonder if you have made too many requests to the service, and your key has been put into a sin-bin? Check their FAQ or support pages. – halfer Aug 27 '12 at 14:08
  • no, i didnt make to many requests. when i create a request to the http://openapi.etsy.com/v2/users/__SELF__" it is working. – Yan Aug 27 '12 at 14:10
  • Hi, how did you get on with this? Any luck? – halfer Sep 19 '12 at 19:19
  • 1
    yes, i contact them for geting full access. for more information visit the google group https://groups.google.com/forum/?fromgroups=#!topic/etsy-api-v2/axIua3d58eY – Yan Sep 21 '12 at 19:27
  • Have you found solution fir this? – Gowri Sep 02 '15 at 06:56

2 Answers2

3

If you are still developing your application you can create listings without gaining full API access, so long as the shop is on your account. Make sure you parse in listings_w as a permission scope when making the first OAUTH request. I have altered the example provided by ETSY in the code below.

    // instantiate the OAuth object
    // OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET are constants holding your key and   secret
    // and are always used when instantiating the OAuth object 
    $oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);

    // make an API request for your temporary credentials
    $req_token = $oauth->getRequestToken("https://openapi.etsy.com/v2/oaut/request_token?scope=email_r%20listings_r%20listings_w", 'oob');

    print $req_token['login_url']."\n";`

Notice the scope=email_r%20listings_r%20listings_w;

Hope this helps

saintybalboa
  • 268
  • 1
  • 2
  • 11
1

Aha, here's the answer. From an Etsy developer:

Your API was not yet approved for full API access. I've fixed that, so you should be able to use those methods now.

Hence, get in touch with the firm, and ask for your key to be approved.

halfer
  • 19,824
  • 17
  • 99
  • 186