Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_QueryParams
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
long li_RespStatusCode
string ls_Id
string ls_Brand_id
string ls_Short_description
string ls_Description
long li_Wholesale_price_cents
long li_Retail_price_cents
string ls_Sale_state
long li_Active
long li_Deleted
string ls_Name
long li_Unit_multiplier
string ls_Taxonomy_typeId
string ls_Taxonomy_typeName
string ls_Created_at
string ls_Updated_at
long j
long li_Count_j
long li_Page
long li_Limit
long i
long li_Count_i

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

loo_QueryParams = create oleobject
li_rc = loo_QueryParams.ConnectToNewObject("Chilkat.JsonObject")

loo_QueryParams.UpdateInt("limit",50)
loo_QueryParams.UpdateInt("page",1)

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

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpParams("GET","https://www.faire.com/api/v1/products",loo_QueryParams,loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_QueryParams
    destroy loo_Resp
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_QueryParams
    destroy loo_Resp
    destroy loo_SbResponseBody
    destroy loo_JResp
    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

li_Page = loo_JResp.IntOf("page")
li_Limit = loo_JResp.IntOf("limit")
i = 0
li_Count_i = loo_JResp.SizeOfArray("products")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Id = loo_JResp.StringOf("products[i].id")
    ls_Brand_id = loo_JResp.StringOf("products[i].brand_id")
    ls_Short_description = loo_JResp.StringOf("products[i].short_description")
    ls_Description = loo_JResp.StringOf("products[i].description")
    li_Wholesale_price_cents = loo_JResp.IntOf("products[i].wholesale_price_cents")
    li_Retail_price_cents = loo_JResp.IntOf("products[i].retail_price_cents")
    ls_Sale_state = loo_JResp.StringOf("products[i].sale_state")
    li_Active = loo_JResp.BoolOf("products[i].active")
    li_Deleted = loo_JResp.BoolOf("products[i].deleted")
    ls_Name = loo_JResp.StringOf("products[i].name")
    li_Unit_multiplier = loo_JResp.IntOf("products[i].unit_multiplier")
    ls_Taxonomy_typeId = loo_JResp.StringOf("products[i].taxonomy_type.id")
    ls_Taxonomy_typeName = loo_JResp.StringOf("products[i].taxonomy_type.name")
    ls_Created_at = loo_JResp.StringOf("products[i].created_at")
    ls_Updated_at = loo_JResp.StringOf("products[i].updated_at")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("products[i].options")
    do while j < li_Count_j
        loo_JResp.J = j
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Http
destroy loo_QueryParams
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp