Sample code for 30+ languages & platforms
Lua

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 Lua Downloads

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()

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

local queryParams = chilkat.JsonObject.new()
queryParams:update_int("limit", 50)
queryParams:update_int("page", 1)

http:set_request_header("X-FAIRE-ACCESS-TOKEN", "<access_token>")

local resp = chilkat.HttpResponse.new()
local success = http:http_params("GET", "https://www.faire.com/api/v1/products", queryParams, resp)
if not success then
    print(http.last_error_text)
    return
end

local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)

local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
    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

local id = ""
local brand_id = ""
local short_description = ""
local description = ""
local wholesale_price_cents = 0
local retail_price_cents = 0
local sale_state = ""
local active = false
local deleted = false
local name = ""
local unit_multiplier = 0
local taxonomy_typeId = ""
local taxonomy_typeName = ""
local created_at = ""
local updated_at = ""
local j = 0
local count_j = 0

local page = jResp:int_of("page")
local limit = jResp:int_of("limit")
local i = 0
local count_i = jResp:size_of_array("products")
while i < count_i do
    jResp.i = i
    id = jResp:string_of("products[i].id")
    brand_id = jResp:string_of("products[i].brand_id")
    short_description = jResp:string_of("products[i].short_description")
    description = jResp:string_of("products[i].description")
    wholesale_price_cents = jResp:int_of("products[i].wholesale_price_cents")
    retail_price_cents = jResp:int_of("products[i].retail_price_cents")
    sale_state = jResp:string_of("products[i].sale_state")
    active = jResp:bool_of("products[i].active")
    deleted = jResp:bool_of("products[i].deleted")
    name = jResp:string_of("products[i].name")
    unit_multiplier = jResp:int_of("products[i].unit_multiplier")
    taxonomy_typeId = jResp:string_of("products[i].taxonomy_type.id")
    taxonomy_typeName = jResp:string_of("products[i].taxonomy_type.name")
    created_at = jResp:string_of("products[i].created_at")
    updated_at = jResp:string_of("products[i].updated_at")
    j = 0
    count_j = jResp:size_of_array("products[i].options")
    while j < count_j do
        jResp.j = j
        j = j + 1
    end

    i = i + 1
end