inakiabt / etsy-php

Etsy API wrapper for PHP
74 stars 59 forks source link

Etsy API question #30

Open Allen209 opened 7 years ago

Allen209 commented 7 years ago

Sorry to ask here but my question is probably really simple for you guys.

I am trying to use the updateListing method to revise listing descriptions...

https://www.etsy.com/developers/documentation/reference/listing#method_updatelisting

I went through the OAuth Authentication process successfully and am able to make an authorized request via the API as per the example in the documentation. I am having problems with the updateListing method. I am trying to revise the description but get the following error…

“Invalid auth/bad request (got a 400, expected HTTP/1.1 20X or a redirect)Expected param 'quantity'.Array”

As per the documentation, the quantity is not required (and is actually depreciated for updateListing). When I use the existing quantity to populate ‘quantity’ in the array (commented out), it complains about another field it expects. I’m not sure why I’m getting an error regarding these fields as they are not required. I would not mind using the existing attributes available from my listing to populate these fields but there is a “shipping_template_id” field which I don’t currently have available. I can’t set it to null because it expects a numeric value. When I set it to 0, it says that it’s not a valid shipping template ID. I must be doing something wrong.

Here is my code (I replaced my actual token and token secrets)…

$access_token = "my token"; $access_token_secret = "my secret";

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

$oauth->setToken($access_token, $access_token_secret);

try {

$url = "https://openapi.etsy.com/v2/private/listings";

$params = array('listing_id' => $result->listing_id,
                                 //'quantity' => $result->quantity,
                                //'title' => $result->title,
                                'description' => $new_description);

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

} catch (OAuthException $e) {

echo $e->getMessage();
echo $oauth->getLastResponse();
echo $oauth->getLastResponseInfo();

}

Amanej commented 7 years ago

"I would not mind using the existing attributes available from my listing to populate these fields but there is a “shipping_template_id” field which I don’t currently have available."

You execute the "find_shipping_templates": https://www.etsy.com/developers/documentation/reference/shippingtemplate#method_findallshippingtemplateentries

The user you run the call against must have a shipping template, or you have to create with that method call.

That will get you the shipping_templates_id to update a listing.

datenfalke commented 6 years ago

You can get the available shipping profiles showing the needed id by using:

print_r($this->api->findAllUserShippingProfiles(array('params' => array('user_id' => 'SELF'))));