简体   繁体   English

通过API更新Etsy列表

[英]Update Etsy listing via API

Using DevDefined.OAuth I'm trying to update existing listing on Etsy. 我正在使用DevDefined.OAuth尝试更新Etsy上的现有列表。 Here is my code: 这是我的代码:

_consumerContext = new OAuthConsumerContext
        {
            ConsumerKey = _apiKey,
            ConsumerSecret = _apiSecret,
            SignatureMethod = SignatureMethod.HmacSha1
        };

_session = new OAuthSession(_consumerContext, "https://openapi.etsy.com/v2/oauth/request_token?scope=transactions_r%20email_r%20listings_r%20transactions_w%20listings_w",
            "https://www.etsy.com/oauth/signin",
            "https://openapi.etsy.com/v2/oauth/access_token");

            _accessToken = new TokenBase();
            _accessToken.ConsumerKey = _apiKey;
            _accessToken.Token = token;
            _accessToken.TokenSecret = tokenSecret;

            IConsumerRequest request = _session.Request(_accessToken)
                .Put()
                .ForUri(new Uri(string.Format("https://openapi.etsy.com/v2/listings/{0}", listing_id)));

            request.Context.QueryParameters.Add("listing_id", listing_id.ToString());
            request.Context.QueryParameters.Add("title", "New title");

            string response = ConsumerRequestExtensions.ReadBody(request);

But I receive 403 response all the time with message "signature_invalid". 但是我一直收到消息“ signature_invalid”的403响应。

When I create listing on Etsy using the same way (except method is POST, not PUT), everything works fine. 当我使用相同的方式在Etsy上创建列表时(方法是POST,而不是PUT),一切正常。

Am I missing something? 我想念什么吗?

You can use the ETSY API method updateInventory to get your product listings updated on ETSY 您可以使用ETSY API方法updateInventory来在ETSY上更新您的产品清单

$oauth = new OAuth(API KEYSTRING, API SHARED STRING);                        
$oauth->setToken($oauth_token, $oauth_token_secret);
$data = $oauth->fetch(
"https://openapi.etsy.com/v2/listings/$listing_id/inventory", [
'products' => $product_data
  'sku_on_property'      => ''
 ],
 OAUTH_HTTP_METHOD_PUT
 );

You can pass the product data as JSON in the $product_data fields to get your products updated on ETSY 您可以在$ product_data字段中以JSON形式传递产品数据,以在ETSY上更新您的产品

It depends what you mean by Update... Much simplified response below, to create the initial listing on Etsy call: 这取决于您在更新...后的含义,以下是在Etsy调用中创建初始清单的简化后的答案:

...
request.Resource = "/listing"
request.Method = Method.POST;
...

Then, to update a listing including stock and price, you must ensure that you have the listing's offering id and product identifier from Etsy, and ensure that this is set in the request data. 然后,要更新包括库存和价格的清单,必须确保您具有Etsy的清单提供的ID和产品标识符,并确保在请求数据中进行了设置。

To get the product_identifier and offering id, make a GET call: 要获取product_identifier和商品ID,请进行GET调用:

...
request.Resource = "/listings/my-etsy-listing-id/inventory"
request.Method = Method.GET;
...

To make further changes for eg Stock or Price, make the following call: 要对库存或价格进行进一步更改,请打以下电话:

...
request.Resource = "/listings/my-etsy-listing-id/inventory"     
request.Method = Method.PUT;
...

To update title/description... call 要更新标题/说明,请致电

...
request.Resource = "/listing/my-etsy-listing_id"
request.Method = Method.PUT;
...

As I said at the beginning, this is very much simplified. 正如我在开始时所说,这已大大简化了。 There is an awful lot of data that you need to send to do stuff in Etsy. 您需要发送大量数据才能在Etsy中进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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