Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set rest [new_CkRest]
# See this example for getting an OAuth1 token for Etsy
set json [new_CkJsonObject]
set success [CkJsonObject_LoadFile $json "qa_data/tokens/etsy.json"]
if {$success == 0} then {
puts "Failed to load previously fetched Etsy OAuth1 access token."
delete_CkRest $rest
delete_CkJsonObject $json
exit
}
set oauth1 [new_CkOAuth1]
CkOAuth1_put_ConsumerKey $oauth1 "app_keystring"
CkOAuth1_put_ConsumerSecret $oauth1 "app_shared_secret"
CkOAuth1_put_Token $oauth1 [CkJsonObject_stringOf $json "oauth_token"]
CkOAuth1_put_TokenSecret $oauth1 [CkJsonObject_stringOf $json "oauth_token_secret"]
CkOAuth1_put_SignatureMethod $oauth1 "HMAC-SHA1"
CkOAuth1_GenNonce $oauth1 16
set autoReconnect 1
set tls 1
set success [CkRest_Connect $rest "openapi.etsy.com" 443 $tls $autoReconnect]
if {$success == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkJsonObject $json
delete_CkOAuth1 $oauth1
exit
}
# Tell the REST object to use the OAuth1 object.
set success [CkRest_SetAuthOAuth1 $rest $oauth1 1]
set jsonText "[{\"product_id\":1999949999,\"property_values\":[],\"offerings\":[{\"offering_id\":9999905883,\"price\":\"36.23\",\"quantity\":1}]}]"
CkRest_AddQueryParam $rest "products" $jsonText
CkRest_AddHeader $rest "Content-Type" "application/x-www-form-urlencoded"
set jsonResponseText [CkRest_fullRequestFormUrlEncoded $rest "PUT" "/v2/listings/228827035/inventory"]
if {[CkRest_get_LastMethodSuccess $rest] == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkJsonObject $json
delete_CkOAuth1 $oauth1
exit
}
set jsonResponse [new_CkJsonObject]
CkJsonObject_Load $jsonResponse $jsonResponseText
CkJsonObject_put_EmitCompact $jsonResponse 0
puts [CkJsonObject_emit $jsonResponse]
puts "Response status code: [CkRest_get_ResponseStatusCode $rest]"
delete_CkRest $rest
delete_CkJsonObject $json
delete_CkOAuth1 $oauth1
delete_CkJsonObject $jsonResponse