Lua
Lua
Update an Inventory Listing using OAuth1 Authentication
See more Etsy Examples
Updates an inventory listing. This example uses OAuth1 authentication instead of providing an api_key=MY_ETSY_KEYSTRING query parameter.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local rest = chilkat.Rest.new()
-- See this example for getting an OAuth1 token for Etsy
local json = chilkat.JsonObject.new()
local success = json:load_file("qa_data/tokens/etsy.json")
if not success then
print("Failed to load previously fetched Etsy OAuth1 access token.")
return
end
local oauth1 = chilkat.OAuth1.new()
oauth1.consumer_key = "app_keystring"
oauth1.consumer_secret = "app_shared_secret"
oauth1.token = json:string_of("oauth_token")
oauth1.token_secret = json:string_of("oauth_token_secret")
oauth1.signature_method = "HMAC-SHA1"
oauth1:gen_nonce(16)
local autoReconnect = true
local tls = true
success = rest:connect("openapi.etsy.com", 443, tls, autoReconnect)
if not success then
print(rest.last_error_text)
return
end
-- Tell the REST object to use the OAuth1 object.
success = rest:set_auth_oauth1(oauth1, true)
local jsonText = "[{\"product_id\":1999949999,\"property_values\":[],\"offerings\":[{\"offering_id\":9999905883,\"price\":\"36.23\",\"quantity\":1}]}]"
rest:add_query_param("products", jsonText)
rest:add_header("Content-Type", "application/x-www-form-urlencoded")
local jsonResponseText = rest:full_request_form_url_encoded("PUT", "/v2/listings/228827035/inventory")
if not rest.last_method_success then
print(rest.last_error_text)
return
end
local jsonResponse = chilkat.JsonObject.new()
jsonResponse:load(jsonResponseText)
jsonResponse.emit_compact = false
print(jsonResponse:emit())
print("Response status code: " .. rest.response_status_code)