Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loHttp = createobject("CkHttp")
// 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
loQueryParams = createobject("CkJsonObject")
loQueryParams.UpdateInt("limit",50)
loQueryParams.UpdateInt("page",1)
loHttp.SetRequestHeader("X-FAIRE-ACCESS-TOKEN","<access_token>")
loResp = createobject("CkHttpResponse")
llSuccess = loHttp.HttpParams("GET","https://www.faire.com/api/v1/products",loQueryParams,loResp)
if (llSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
release loQueryParams
release loResp
return
endif
loSbResponseBody = createobject("CkStringBuilder")
loResp.GetBodySb(loSbResponseBody)
loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
? "Response Header:"
? loResp.Header
? "Failed."
release loHttp
release loQueryParams
release loResp
release loSbResponseBody
release loJResp
return
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
lnPage = loJResp.IntOf("page")
lnLimit = loJResp.IntOf("limit")
i = 0
lnCount_i = loJResp.SizeOfArray("products")
do while i < lnCount_i
loJResp.I = i
lcId = loJResp.StringOf("products[i].id")
lcBrand_id = loJResp.StringOf("products[i].brand_id")
lcShort_description = loJResp.StringOf("products[i].short_description")
lcDescription = loJResp.StringOf("products[i].description")
lnWholesale_price_cents = loJResp.IntOf("products[i].wholesale_price_cents")
lnRetail_price_cents = loJResp.IntOf("products[i].retail_price_cents")
lcSale_state = loJResp.StringOf("products[i].sale_state")
llActive = loJResp.BoolOf("products[i].active")
llDeleted = loJResp.BoolOf("products[i].deleted")
lcName = loJResp.StringOf("products[i].name")
lnUnit_multiplier = loJResp.IntOf("products[i].unit_multiplier")
lcTaxonomy_typeId = loJResp.StringOf("products[i].taxonomy_type.id")
lcTaxonomy_typeName = loJResp.StringOf("products[i].taxonomy_type.name")
lcCreated_at = loJResp.StringOf("products[i].created_at")
lcUpdated_at = loJResp.StringOf("products[i].updated_at")
j = 0
lnCount_j = loJResp.SizeOfArray("products[i].options")
do while j < lnCount_j
loJResp.J = j
j = j + 1
enddo
i = i + 1
enddo
release loHttp
release loQueryParams
release loResp
release loSbResponseBody
release loJResp