PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
oleobject loo_Json
oleobject loo_Oauth1
integer li_AutoReconnect
integer li_Tls
string ls_JsonText
string ls_JsonResponseText
oleobject loo_JsonResponse
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
// See this example for getting an OAuth1 token for Etsy
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Json.LoadFile("qa_data/tokens/etsy.json")
if li_Success = 0 then
Write-Debug "Failed to load previously fetched Etsy OAuth1 access token."
destroy loo_Rest
destroy loo_Json
return
end if
loo_Oauth1 = create oleobject
li_rc = loo_Oauth1.ConnectToNewObject("Chilkat.OAuth1")
loo_Oauth1.ConsumerKey = "app_keystring"
loo_Oauth1.ConsumerSecret = "app_shared_secret"
loo_Oauth1.Token = loo_Json.StringOf("oauth_token")
loo_Oauth1.TokenSecret = loo_Json.StringOf("oauth_token_secret")
loo_Oauth1.SignatureMethod = "HMAC-SHA1"
loo_Oauth1.GenNonce(16)
li_AutoReconnect = 1
li_Tls = 1
li_Success = loo_Rest.Connect("openapi.etsy.com",443,li_Tls,li_AutoReconnect)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_Json
destroy loo_Oauth1
return
end if
// Tell the REST object to use the OAuth1 object.
li_Success = loo_Rest.SetAuthOAuth1(loo_Oauth1,1)
ls_JsonText = "[{~"product_id~":1999949999,~"property_values~":[],~"offerings~":[{~"offering_id~":9999905883,~"price~":~"36.23~",~"quantity~":1}]}]"
loo_Rest.AddQueryParam("products",ls_JsonText)
loo_Rest.AddHeader("Content-Type","application/x-www-form-urlencoded")
ls_JsonResponseText = loo_Rest.FullRequestFormUrlEncoded("PUT","/v2/listings/228827035/inventory")
if loo_Rest.LastMethodSuccess = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_Json
destroy loo_Oauth1
return
end if
loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat.JsonObject")
loo_JsonResponse.Load(ls_JsonResponseText)
loo_JsonResponse.EmitCompact = 0
Write-Debug loo_JsonResponse.Emit()
Write-Debug "Response status code: " + string(loo_Rest.ResponseStatusCode)
destroy loo_Rest
destroy loo_Json
destroy loo_Oauth1
destroy loo_JsonResponse