DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vQueryParams
Handle hoQueryParams
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sId
String sBrand_id
String sShort_description
String sDescription
Integer iWholesale_price_cents
Integer iRetail_price_cents
String sSale_state
Boolean iActive
Boolean iDeleted
String sName
Integer iUnit_multiplier
String sTaxonomy_typeId
String sTaxonomy_typeName
String sCreated_at
String sUpdated_at
Integer j
Integer iCount_j
Integer iPage
Integer iLimit
Integer i
Integer iCount_i
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// 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
Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
If (Not(IsComObjectCreated(hoQueryParams))) Begin
Send CreateComObject of hoQueryParams
End
Get ComUpdateInt Of hoQueryParams "limit" 50 To iSuccess
Get ComUpdateInt Of hoQueryParams "page" 1 To iSuccess
Send ComSetRequestHeader To hoHttp "X-FAIRE-ACCESS-TOKEN" "<access_token>"
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoQueryParams to vQueryParams
Get pvComObject of hoResp to vResp
Get ComHttpParams Of hoHttp "GET" "https://www.faire.com/api/v1/products" vQueryParams vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
// 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
Get ComIntOf Of hoJResp "page" To iPage
Get ComIntOf Of hoJResp "limit" To iLimit
Move 0 To i
Get ComSizeOfArray Of hoJResp "products" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "products[i].id" To sId
Get ComStringOf Of hoJResp "products[i].brand_id" To sBrand_id
Get ComStringOf Of hoJResp "products[i].short_description" To sShort_description
Get ComStringOf Of hoJResp "products[i].description" To sDescription
Get ComIntOf Of hoJResp "products[i].wholesale_price_cents" To iWholesale_price_cents
Get ComIntOf Of hoJResp "products[i].retail_price_cents" To iRetail_price_cents
Get ComStringOf Of hoJResp "products[i].sale_state" To sSale_state
Get ComBoolOf Of hoJResp "products[i].active" To iActive
Get ComBoolOf Of hoJResp "products[i].deleted" To iDeleted
Get ComStringOf Of hoJResp "products[i].name" To sName
Get ComIntOf Of hoJResp "products[i].unit_multiplier" To iUnit_multiplier
Get ComStringOf Of hoJResp "products[i].taxonomy_type.id" To sTaxonomy_typeId
Get ComStringOf Of hoJResp "products[i].taxonomy_type.name" To sTaxonomy_typeName
Get ComStringOf Of hoJResp "products[i].created_at" To sCreated_at
Get ComStringOf Of hoJResp "products[i].updated_at" To sUpdated_at
Move 0 To j
Get ComSizeOfArray Of hoJResp "products[i].options" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Move (j + 1) To j
Loop
Move (i + 1) To i
Loop
End_Procedure