Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Faire - Get All ProductsSee more Faire ExamplesRetrieves a list of products, ordered ascending by updated_at. By default, it only returns non-deleted products. For more information, see https://faire.github.io/external-api-docs/#get-all-products
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 http: HCkHttp; success: Boolean; 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 // 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 := CkHttp_QuickRequestParams(http,'GET','https://www.faire.com/api/v1/products',queryParams); if (CkHttp_getLastMethodSuccess(http) = 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.'); CkHttpResponse_Dispose(resp); Exit; end; CkHttpResponse_Dispose(resp); // 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); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.