AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oRest = ObjCreate("Chilkat.Rest")
; See this example for getting an OAuth1 token for Etsy
$oJson = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oJson.LoadFile("qa_data/tokens/etsy.json")
If ($bSuccess = False) Then
ConsoleWrite("Failed to load previously fetched Etsy OAuth1 access token." & @CRLF)
Exit
EndIf
$oOauth1 = ObjCreate("Chilkat.OAuth1")
$oOauth1.ConsumerKey = "app_keystring"
$oOauth1.ConsumerSecret = "app_shared_secret"
$oOauth1.Token = $oJson.StringOf("oauth_token")
$oOauth1.TokenSecret = $oJson.StringOf("oauth_token_secret")
$oOauth1.SignatureMethod = "HMAC-SHA1"
$oOauth1.GenNonce(16)
Local $bAutoReconnect = True
Local $bTls = True
$bSuccess = $oRest.Connect("openapi.etsy.com",443,$bTls,$bAutoReconnect)
If ($bSuccess = False) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
; Tell the REST object to use the OAuth1 object.
$bSuccess = $oRest.SetAuthOAuth1($oOauth1,True)
Local $sJsonText = "[{""product_id"":1999949999,""property_values"":[],""offerings"":[{""offering_id"":9999905883,""price"":""36.23"",""quantity"":1}]}]"
$oRest.AddQueryParam("products",$sJsonText)
$oRest.AddHeader("Content-Type","application/x-www-form-urlencoded")
Local $sJsonResponseText = $oRest.FullRequestFormUrlEncoded("PUT","/v2/listings/228827035/inventory")
If ($oRest.LastMethodSuccess = False) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
$oJsonResponse = ObjCreate("Chilkat.JsonObject")
$oJsonResponse.Load($sJsonResponseText)
$oJsonResponse.EmitCompact = False
ConsoleWrite($oJsonResponse.Emit() & @CRLF)
ConsoleWrite("Response status code: " & $oRest.ResponseStatusCode & @CRLF)