Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loRest
LOCAL loJson
LOCAL loOauth1
LOCAL lnAutoReconnect
LOCAL lnTls
LOCAL lcJsonText
LOCAL lcJsonResponseText
LOCAL loJsonResponse
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loRest = CreateObject('Chilkat.Rest')
* See this example for getting an OAuth1 token for Etsy
loJson = CreateObject('Chilkat.JsonObject')
lnSuccess = loJson.LoadFile("qa_data/tokens/etsy.json")
IF (lnSuccess = 0) THEN
? "Failed to load previously fetched Etsy OAuth1 access token."
RELEASE loRest
RELEASE loJson
CANCEL
ENDIF
loOauth1 = CreateObject('Chilkat.OAuth1')
loOauth1.ConsumerKey = "app_keystring"
loOauth1.ConsumerSecret = "app_shared_secret"
loOauth1.Token = loJson.StringOf("oauth_token")
loOauth1.TokenSecret = loJson.StringOf("oauth_token_secret")
loOauth1.SignatureMethod = "HMAC-SHA1"
loOauth1.GenNonce(16)
lnAutoReconnect = 1
lnTls = 1
lnSuccess = loRest.Connect("openapi.etsy.com",443,lnTls,lnAutoReconnect)
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loJson
RELEASE loOauth1
CANCEL
ENDIF
* Tell the REST object to use the OAuth1 object.
lnSuccess = loRest.SetAuthOAuth1(loOauth1,1)
lcJsonText = '[{"product_id":1999949999,"property_values":[],"offerings":[{"offering_id":9999905883,"price":"36.23","quantity":1}]}]'
loRest.AddQueryParam("products",lcJsonText)
loRest.AddHeader("Content-Type","application/x-www-form-urlencoded")
lcJsonResponseText = loRest.FullRequestFormUrlEncoded("PUT","/v2/listings/228827035/inventory")
IF (loRest.LastMethodSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loJson
RELEASE loOauth1
CANCEL
ENDIF
loJsonResponse = CreateObject('Chilkat.JsonObject')
loJsonResponse.Load(lcJsonResponseText)
loJsonResponse.EmitCompact = 0
? loJsonResponse.Emit()
? "Response status code: " + STR(loRest.ResponseStatusCode)
RELEASE loRest
RELEASE loJson
RELEASE loOauth1
RELEASE loJsonResponse