Xbase++
Xbase++
Etsy: Get the Inventory for a Listing
See more Etsy Examples
Gets the inventory for a listing.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL nProduct_id
LOCAL j
LOCAL nCount_j
LOCAL nOffering_id
LOCAL nPriceAmount
LOCAL nPriceDivisor
LOCAL cPriceCurrency_code
LOCAL cPriceCurrency_formatted_short
LOCAL cPriceCurrency_formatted_long
LOCAL cPriceCurrency_formatted_raw
LOCAL nQuantity
LOCAL nCount
LOCAL cParamsListing_id
LOCAL nParamsWrite_missing_inventory
LOCAL cV_type
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Implements the following CURL command:
// curl -X GET \
// https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
ENDIF
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "count": 1,
// "results": {
// "products": [
// {
// "product_id": 3361120103,
// "property_values": [
// ],
// "offerings": [
// {
// "offering_id": 3579642570,
// "price": {
// "amount": 16000,
// "divisor": 100,
// "currency_code": "USD",
// "currency_formatted_short": "$160.00",
// "currency_formatted_long": "$160.00 USD",
// "currency_formatted_raw": "160.00"
// },
// "quantity": 1
// }
// ]
// }
// ]
// },
// "params": {
// "listing_id": "720138253",
// "write_missing_inventory": false
// },
// "type": "ListingInventory",
// "pagination": {}
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
nCount := oJResp:IntOf("count")
cParamsListing_id := oJResp:StringOf("params.listing_id")
nParamsWrite_missing_inventory := oJResp:BoolOf("params.write_missing_inventory")
cV_type := oJResp:StringOf("type")
i := 0
nCount_i := oJResp:SizeOfArray("results.products")
DO WHILE i < nCount_i
oJResp:I := i
nProduct_id := oJResp:IntOf("results.products[i].product_id")
j := 0
nCount_j := oJResp:SizeOfArray("results.products[i].property_values")
DO WHILE j < nCount_j
oJResp:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJResp:SizeOfArray("results.products[i].offerings")
DO WHILE j < nCount_j
oJResp:J := j
nOffering_id := oJResp:IntOf("results.products[i].offerings[j].offering_id")
nPriceAmount := oJResp:IntOf("results.products[i].offerings[j].price.amount")
nPriceDivisor := oJResp:IntOf("results.products[i].offerings[j].price.divisor")
cPriceCurrency_code := oJResp:StringOf("results.products[i].offerings[j].price.currency_code")
cPriceCurrency_formatted_short := oJResp:StringOf("results.products[i].offerings[j].price.currency_formatted_short")
cPriceCurrency_formatted_long := oJResp:StringOf("results.products[i].offerings[j].price.currency_formatted_long")
cPriceCurrency_formatted_raw := oJResp:StringOf("results.products[i].offerings[j].price.currency_formatted_raw")
nQuantity := oJResp:IntOf("results.products[i].offerings[j].quantity")
j := j + 1
ENDDO
i := i + 1
ENDDO
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()