Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL oJson
LOCAL oOauth1
LOCAL nAutoReconnect
LOCAL nTls
LOCAL cJsonText
LOCAL cJsonResponseText
LOCAL oJsonResponse
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oRest := CreateObject("Chilkat.Rest")
// See this example for getting an OAuth1 token for Etsy
oJson := CreateObject("Chilkat.JsonObject")
nSuccess := oJson:LoadFile("qa_data/tokens/etsy.json")
IF (nSuccess == 0)
? "Failed to load previously fetched Etsy OAuth1 access token."
oRest:destroy()
oJson:destroy()
RETURN
ENDIF
oOauth1 := CreateObject("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)
nAutoReconnect := 1
nTls := 1
nSuccess := oRest:Connect("openapi.etsy.com", 443, nTls, nAutoReconnect)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oJson:destroy()
oOauth1:destroy()
RETURN
ENDIF
// Tell the REST object to use the OAuth1 object.
nSuccess := oRest:SetAuthOAuth1(oOauth1, 1)
cJsonText := '[{"product_id":1999949999,"property_values":[],"offerings":[{"offering_id":9999905883,"price":"36.23","quantity":1}]}]'
oRest:AddQueryParam("products", cJsonText)
oRest:AddHeader("Content-Type", "application/x-www-form-urlencoded")
cJsonResponseText := oRest:FullRequestFormUrlEncoded("PUT", "/v2/listings/228827035/inventory")
IF (oRest:LastMethodSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oJson:destroy()
oOauth1:destroy()
RETURN
ENDIF
oJsonResponse := CreateObject("Chilkat.JsonObject")
oJsonResponse:Load(cJsonResponseText)
oJsonResponse:EmitCompact := 0
? oJsonResponse:Emit()
? "Response status code: " + Str(oRest:ResponseStatusCode)
oRest:destroy()
oJson:destroy()
oOauth1:destroy()
oJsonResponse:destroy()