简体   繁体   中英

Etsy API updateListing

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();

}

$args = array(
                                    'data' => array(
                                        "quantity" => $quantity,
                                        "title" => $title,
                                        "description" => strip_tags($description),
                                        "price" => $price,
                                        "materials" => $materials,
                                        "shipping_template_id" =>(int)$shippingTemplateId,

                                        "non_taxable" => false,
                                        "state" => "$ced_etsy_upload_product_type",
                                        "processing_min" => 1,
                                        "processing_max" => 3,

                                        "taxonomy_id" => (int)$categoryId,
                                        "who_made" => $who_made,
                                        "is_supply" => true,
                                        "when_made" => $when_made,

                                    )
                                );

Please try this may be this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM