Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oQueryParams
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cId
LOCAL cBrand_id
LOCAL cShort_description
LOCAL cDescription
LOCAL nWholesale_price_cents
LOCAL nRetail_price_cents
LOCAL cSale_state
LOCAL nActive
LOCAL nDeleted
LOCAL cName
LOCAL nUnit_multiplier
LOCAL cTaxonomy_typeId
LOCAL cTaxonomy_typeName
LOCAL cCreated_at
LOCAL cUpdated_at
LOCAL j
LOCAL nCount_j
LOCAL nPage
LOCAL nLimit
LOCAL i
LOCAL nCount_i

nSuccess := 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("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 := CreateObject("Chilkat.JsonObject")
oQueryParams:UpdateInt("limit", 50)
oQueryParams:UpdateInt("page", 1)

oHttp:SetRequestHeader("X-FAIRE-ACCESS-TOKEN", "<access_token>")

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpParams("GET", "https://www.faire.com/api/v1/products", oQueryParams, oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oQueryParams:destroy()
    oResp:destroy()
    RETURN
ENDIF

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)

oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0

? "Response Body:"
? oJResp:Emit()

nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
    ? "Response Header:"
    ? oResp:Header
    ? "Failed."
    oHttp:destroy()
    oQueryParams:destroy()
    oResp:destroy()
    oSbResponseBody:destroy()
    oJResp:destroy()
    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

nPage := oJResp:IntOf("page")
nLimit := oJResp:IntOf("limit")
i := 0
nCount_i := oJResp:SizeOfArray("products")
DO WHILE i < nCount_i
    oJResp:I := i
    cId := oJResp:StringOf("products[i].id")
    cBrand_id := oJResp:StringOf("products[i].brand_id")
    cShort_description := oJResp:StringOf("products[i].short_description")
    cDescription := oJResp:StringOf("products[i].description")
    nWholesale_price_cents := oJResp:IntOf("products[i].wholesale_price_cents")
    nRetail_price_cents := oJResp:IntOf("products[i].retail_price_cents")
    cSale_state := oJResp:StringOf("products[i].sale_state")
    nActive := oJResp:BoolOf("products[i].active")
    nDeleted := oJResp:BoolOf("products[i].deleted")
    cName := oJResp:StringOf("products[i].name")
    nUnit_multiplier := oJResp:IntOf("products[i].unit_multiplier")
    cTaxonomy_typeId := oJResp:StringOf("products[i].taxonomy_type.id")
    cTaxonomy_typeName := oJResp:StringOf("products[i].taxonomy_type.name")
    cCreated_at := oJResp:StringOf("products[i].created_at")
    cUpdated_at := oJResp:StringOf("products[i].updated_at")
    j := 0
    nCount_j := oJResp:SizeOfArray("products[i].options")
    DO WHILE j < nCount_j
        oJResp:J := j
        j := j + 1
    ENDDO
    i := i + 1
ENDDO

oHttp:destroy()
oQueryParams:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()