AutoIt
AutoIt
Etsy: Get the Inventory for a Listing
See more Etsy Examples
Gets the inventory for a listing.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("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 = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING",$oSbResponseBody)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oHttp.LastHeader & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
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
Local $iProduct_id
Local $iJ
Local $iCount_j
Local $iOffering_id
Local $iPriceAmount
Local $iPriceDivisor
Local $sPriceCurrency_code
Local $sPriceCurrency_formatted_short
Local $sPriceCurrency_formatted_long
Local $sPriceCurrency_formatted_raw
Local $iQuantity
Local $iCount = $oJResp.IntOf("count")
Local $sParamsListing_id = $oJResp.StringOf("params.listing_id")
Local $bParamsWrite_missing_inventory = $oJResp.BoolOf("params.write_missing_inventory")
Local $sV_type = $oJResp.StringOf("type")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("results.products")
While $i < $iCount_i
$oJResp.I = $i
$iProduct_id = $oJResp.IntOf("results.products[i].product_id")
$iJ = 0
$iCount_j = $oJResp.SizeOfArray("results.products[i].property_values")
While $iJ < $iCount_j
$oJResp.J = $iJ
$iJ = $iJ + 1
Wend
$iJ = 0
$iCount_j = $oJResp.SizeOfArray("results.products[i].offerings")
While $iJ < $iCount_j
$oJResp.J = $iJ
$iOffering_id = $oJResp.IntOf("results.products[i].offerings[j].offering_id")
$iPriceAmount = $oJResp.IntOf("results.products[i].offerings[j].price.amount")
$iPriceDivisor = $oJResp.IntOf("results.products[i].offerings[j].price.divisor")
$sPriceCurrency_code = $oJResp.StringOf("results.products[i].offerings[j].price.currency_code")
$sPriceCurrency_formatted_short = $oJResp.StringOf("results.products[i].offerings[j].price.currency_formatted_short")
$sPriceCurrency_formatted_long = $oJResp.StringOf("results.products[i].offerings[j].price.currency_formatted_long")
$sPriceCurrency_formatted_raw = $oJResp.StringOf("results.products[i].offerings[j].price.currency_formatted_raw")
$iQuantity = $oJResp.IntOf("results.products[i].offerings[j].quantity")
$iJ = $iJ + 1
Wend
$i = $i + 1
Wend