Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, HttpResponse, JsonObject;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
queryParams: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
id: PWideChar;
brand_id: PWideChar;
short_description: PWideChar;
description: PWideChar;
wholesale_price_cents: Integer;
retail_price_cents: Integer;
sale_state: PWideChar;
active: Boolean;
deleted: Boolean;
name: PWideChar;
unit_multiplier: Integer;
taxonomy_typeId: PWideChar;
taxonomy_typeName: PWideChar;
created_at: PWideChar;
updated_at: PWideChar;
j: Integer;
count_j: Integer;
page: Integer;
limit: Integer;
i: Integer;
count_i: Integer;

begin
success := False;

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

http := CkHttp_Create();

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

queryParams := CkJsonObject_Create();
CkJsonObject_UpdateInt(queryParams,'limit',50);
CkJsonObject_UpdateInt(queryParams,'page',1);

CkHttp_SetRequestHeader(http,'X-FAIRE-ACCESS-TOKEN','<access_token>');

resp := CkHttpResponse_Create();
success := CkHttp_HttpParams(http,'GET','https://www.faire.com/api/v1/products',queryParams,resp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    Exit;
  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

page := CkJsonObject_IntOf(jResp,'page');
limit := CkJsonObject_IntOf(jResp,'limit');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'products');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    id := CkJsonObject__stringOf(jResp,'products[i].id');
    brand_id := CkJsonObject__stringOf(jResp,'products[i].brand_id');
    short_description := CkJsonObject__stringOf(jResp,'products[i].short_description');
    description := CkJsonObject__stringOf(jResp,'products[i].description');
    wholesale_price_cents := CkJsonObject_IntOf(jResp,'products[i].wholesale_price_cents');
    retail_price_cents := CkJsonObject_IntOf(jResp,'products[i].retail_price_cents');
    sale_state := CkJsonObject__stringOf(jResp,'products[i].sale_state');
    active := CkJsonObject_BoolOf(jResp,'products[i].active');
    deleted := CkJsonObject_BoolOf(jResp,'products[i].deleted');
    name := CkJsonObject__stringOf(jResp,'products[i].name');
    unit_multiplier := CkJsonObject_IntOf(jResp,'products[i].unit_multiplier');
    taxonomy_typeId := CkJsonObject__stringOf(jResp,'products[i].taxonomy_type.id');
    taxonomy_typeName := CkJsonObject__stringOf(jResp,'products[i].taxonomy_type.name');
    created_at := CkJsonObject__stringOf(jResp,'products[i].created_at');
    updated_at := CkJsonObject__stringOf(jResp,'products[i].updated_at');
    j := 0;
    count_j := CkJsonObject_SizeOfArray(jResp,'products[i].options');
    while j < count_j do
      begin
        CkJsonObject_putJ(jResp,j);
        j := j + 1;
      end;

    i := i + 1;
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(queryParams);
CkHttpResponse_Dispose(resp);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

end;