AutoIt
AutoIt
Faire - Get All Products
See more Faire Examples
Retrieves a list of products, ordered ascending by updated_at. By default, it only returns non-deleted products.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 -H "X-FAIRE-ACCESS-TOKEN: <access_token>" -d "limit=50" -d "page=1" https://www.faire.com/api/v1/products
; Use the following online tool to generate HTTP code from a CURL command
; Convert a cURL Command to HTTP Source Code
$oQueryParams = ObjCreate("Chilkat.JsonObject")
$oQueryParams.UpdateInt("limit",50)
$oQueryParams.UpdateInt("page",1)
$oHttp.SetRequestHeader "X-FAIRE-ACCESS-TOKEN","<access_token>"
$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpParams("GET","https://www.faire.com/api/v1/products",$oQueryParams,$oResp)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oResp.Header & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)
; {
; "page": 1,
; "limit": 50,
; "products": [
; {
; "id": "p_123",
; "brand_id": "b_abc",
; "short_description": "Our candles smell fantastic. Want to know how good? Read our description!",
; "description": "Glad you decided to read our description! We have significantly more characters to describe to you just how good our candles smell.",
; "wholesale_price_cents": 500,
; "retail_price_cents": 1000,
; "sale_state": "FOR_SALE",
; "active": true,
; "deleted": false,
; "name": "Faire's fantastic candle",
; "unit_multiplier": 8,
; "taxonomy_type": {
; "id": "tt_23nl3bzl00",
; "name": "Votive Candle"
; },
; "options": [
; ],
; "created_at": "20190314T000915.000Z",
; "updated_at": "20190315T000915.000Z"
; }
; ]
; }
; 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 $sId
Local $sBrand_id
Local $short_description
Local $sDescription
Local $iWholesale_price_cents
Local $iRetail_price_cents
Local $sale_state
Local $bActive
Local $bDeleted
Local $sName
Local $iUnit_multiplier
Local $sTaxonomy_typeId
Local $sTaxonomy_typeName
Local $sCreated_at
Local $sUpdated_at
Local $iJ
Local $iCount_j
Local $iPage = $oJResp.IntOf("page")
Local $iLimit = $oJResp.IntOf("limit")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("products")
While $i < $iCount_i
$oJResp.I = $i
$sId = $oJResp.StringOf("products[i].id")
$sBrand_id = $oJResp.StringOf("products[i].brand_id")
$short_description = $oJResp.StringOf("products[i].short_description")
$sDescription = $oJResp.StringOf("products[i].description")
$iWholesale_price_cents = $oJResp.IntOf("products[i].wholesale_price_cents")
$iRetail_price_cents = $oJResp.IntOf("products[i].retail_price_cents")
$sale_state = $oJResp.StringOf("products[i].sale_state")
$bActive = $oJResp.BoolOf("products[i].active")
$bDeleted = $oJResp.BoolOf("products[i].deleted")
$sName = $oJResp.StringOf("products[i].name")
$iUnit_multiplier = $oJResp.IntOf("products[i].unit_multiplier")
$sTaxonomy_typeId = $oJResp.StringOf("products[i].taxonomy_type.id")
$sTaxonomy_typeName = $oJResp.StringOf("products[i].taxonomy_type.name")
$sCreated_at = $oJResp.StringOf("products[i].created_at")
$sUpdated_at = $oJResp.StringOf("products[i].updated_at")
$iJ = 0
$iCount_j = $oJResp.SizeOfArray("products[i].options")
While $iJ < $iCount_j
$oJResp.J = $iJ
$iJ = $iJ + 1
Wend
$i = $i + 1
Wend