Tcl
Tcl
Etsy: Get the Inventory for a Listing
See more Etsy Examples
Gets the inventory for a listing.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
# Implements the following CURL command:
# curl -X GET \
# https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING
set sbResponseBody [new_CkStringBuilder]
set success [CkHttp_QuickGetSb $http "https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING" $sbResponseBody]
if {$success == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
exit
}
set jResp [new_CkJsonObject]
CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0
puts "Response Body:"
puts [CkJsonObject_emit $jResp]
set respStatusCode [CkHttp_get_LastStatus $http]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
puts "Response Header:"
puts [CkHttp_lastHeader $http]
puts "Failed."
delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp
exit
}
# 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
set count [CkJsonObject_IntOf $jResp "count"]
set paramsListing_id [CkJsonObject_stringOf $jResp "params.listing_id"]
set paramsWrite_missing_inventory [CkJsonObject_BoolOf $jResp "params.write_missing_inventory"]
set v_type [CkJsonObject_stringOf $jResp "type"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "results.products"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set product_id [CkJsonObject_IntOf $jResp "results.products[i].product_id"]
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "results.products[i].property_values"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "results.products[i].offerings"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set offering_id [CkJsonObject_IntOf $jResp "results.products[i].offerings[j].offering_id"]
set priceAmount [CkJsonObject_IntOf $jResp "results.products[i].offerings[j].price.amount"]
set priceDivisor [CkJsonObject_IntOf $jResp "results.products[i].offerings[j].price.divisor"]
set priceCurrency_code [CkJsonObject_stringOf $jResp "results.products[i].offerings[j].price.currency_code"]
set priceCurrency_formatted_short [CkJsonObject_stringOf $jResp "results.products[i].offerings[j].price.currency_formatted_short"]
set priceCurrency_formatted_long [CkJsonObject_stringOf $jResp "results.products[i].offerings[j].price.currency_formatted_long"]
set priceCurrency_formatted_raw [CkJsonObject_stringOf $jResp "results.products[i].offerings[j].price.currency_formatted_raw"]
set quantity [CkJsonObject_IntOf $jResp "results.products[i].offerings[j].quantity"]
set j [expr $j + 1]
}
set i [expr $i + 1]
}
delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp