Sample code for 30+ languages & platforms
Xojo Plugin

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 Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

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

Dim http As New 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

Dim queryParams As New Chilkat.JsonObject
success = queryParams.UpdateInt("limit",50)
success = queryParams.UpdateInt("page",1)

http.SetRequestHeader "X-FAIRE-ACCESS-TOKEN","<access_token>"

Dim resp As New Chilkat.HttpResponse
success = http.HttpParams("GET","https://www.faire.com/api/v1/products",queryParams,resp)
If (success = False) Then
    System.DebugLog(http.LastErrorText)
    Return
End If

Dim sbResponseBody As New Chilkat.StringBuilder
success = resp.GetBodySb(sbResponseBody)

Dim jResp As New Chilkat.JsonObject
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

System.DebugLog("Response Body:")
System.DebugLog(jResp.Emit())

Dim respStatusCode As Int32
respStatusCode = resp.StatusCode
System.DebugLog("Response Status Code = " + Str(respStatusCode))
If (respStatusCode >= 400) Then
    System.DebugLog("Response Header:")
    System.DebugLog(resp.Header)
    System.DebugLog("Failed.")
    Return
End If

// 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

Dim id As String
Dim brand_id As String
Dim short_description As String
Dim description As String
Dim wholesale_price_cents As Int32
Dim retail_price_cents As Int32
Dim sale_state As String
Dim active As Boolean
Dim deleted As Boolean
Dim name As String
Dim unit_multiplier As Int32
Dim taxonomy_typeId As String
Dim taxonomy_typeName As String
Dim created_at As String
Dim updated_at As String
Dim j As Int32
Dim count_j As Int32

Dim page As Int32
page = jResp.IntOf("page")
Dim limit As Int32
limit = jResp.IntOf("limit")
Dim i As Int32
i = 0
Dim count_i As Int32
count_i = jResp.SizeOfArray("products")
While i < count_i
    jResp.I = i
    id = jResp.StringOf("products[i].id")
    brand_id = jResp.StringOf("products[i].brand_id")
    short_description = jResp.StringOf("products[i].short_description")
    description = jResp.StringOf("products[i].description")
    wholesale_price_cents = jResp.IntOf("products[i].wholesale_price_cents")
    retail_price_cents = jResp.IntOf("products[i].retail_price_cents")
    sale_state = jResp.StringOf("products[i].sale_state")
    active = jResp.BoolOf("products[i].active")
    deleted = jResp.BoolOf("products[i].deleted")
    name = jResp.StringOf("products[i].name")
    unit_multiplier = jResp.IntOf("products[i].unit_multiplier")
    taxonomy_typeId = jResp.StringOf("products[i].taxonomy_type.id")
    taxonomy_typeName = jResp.StringOf("products[i].taxonomy_type.name")
    created_at = jResp.StringOf("products[i].created_at")
    updated_at = jResp.StringOf("products[i].updated_at")
    j = 0
    count_j = jResp.SizeOfArray("products[i].options")
    While j < count_j
        jResp.J = j
        j = j + 1
    Wend
    i = i + 1
Wend