Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loQueryParams
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcId
LOCAL lcBrand_id
LOCAL lcShort_description
LOCAL lcDescription
LOCAL lnWholesale_price_cents
LOCAL lnRetail_price_cents
LOCAL lcSale_state
LOCAL lnActive
LOCAL lnDeleted
LOCAL lcName
LOCAL lnUnit_multiplier
LOCAL lcTaxonomy_typeId
LOCAL lcTaxonomy_typeName
LOCAL lcCreated_at
LOCAL lcUpdated_at
LOCAL j
LOCAL lnCount_j
LOCAL lnPage
LOCAL lnLimit
LOCAL i
LOCAL lnCount_i

lnSuccess = 0

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

loHttp = 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

loQueryParams = CreateObject('Chilkat.JsonObject')
loQueryParams.UpdateInt("limit",50)
loQueryParams.UpdateInt("page",1)

loHttp.SetRequestHeader("X-FAIRE-ACCESS-TOKEN","<access_token>")

loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpParams("GET","https://www.faire.com/api/v1/products",loQueryParams,loResp)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loQueryParams
    RELEASE loResp
    CANCEL
ENDIF

loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)

loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "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
    CANCEL
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")
    lnActive = loJResp.BoolOf("products[i].active")
    lnDeleted = 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