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
(Tcl) 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
load ./chilkat.dll # This example assumes the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set http [new_CkHttp] # 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 set queryParams [new_CkJsonObject] CkJsonObject_UpdateInt $queryParams "limit" 50 CkJsonObject_UpdateInt $queryParams "page" 1 CkHttp_SetRequestHeader $http "X-FAIRE-ACCESS-TOKEN" "<access_token>" # resp is a CkHttpResponse set resp [CkHttp_QuickRequestParams $http "GET" "https://www.faire.com/api/v1/products" $queryParams] if {[CkHttp_get_LastMethodSuccess $http] == 0} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkJsonObject $queryParams exit } set sbResponseBody [new_CkStringBuilder] CkHttpResponse_GetBodySb $resp $sbResponseBody set jResp [new_CkJsonObject] CkJsonObject_LoadSb $jResp $sbResponseBody CkJsonObject_put_EmitCompact $jResp 0 puts "Response Body:" puts [CkJsonObject_emit $jResp] set respStatusCode [CkHttpResponse_get_StatusCode $resp] puts "Response Status Code = $respStatusCode" if {$respStatusCode >= 400} then { puts "Response Header:" puts [CkHttpResponse_header $resp] puts "Failed." delete_CkHttpResponse $resp delete_CkHttp $http delete_CkJsonObject $queryParams delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp exit } delete_CkHttpResponse $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 set page [CkJsonObject_IntOf $jResp "page"] set limit [CkJsonObject_IntOf $jResp "limit"] set i 0 set count_i [CkJsonObject_SizeOfArray $jResp "products"] while {$i < $count_i} { CkJsonObject_put_I $jResp $i set id [CkJsonObject_stringOf $jResp "products[i].id"] set brand_id [CkJsonObject_stringOf $jResp "products[i].brand_id"] set short_description [CkJsonObject_stringOf $jResp "products[i].short_description"] set description [CkJsonObject_stringOf $jResp "products[i].description"] set wholesale_price_cents [CkJsonObject_IntOf $jResp "products[i].wholesale_price_cents"] set retail_price_cents [CkJsonObject_IntOf $jResp "products[i].retail_price_cents"] set sale_state [CkJsonObject_stringOf $jResp "products[i].sale_state"] set active [CkJsonObject_BoolOf $jResp "products[i].active"] set deleted [CkJsonObject_BoolOf $jResp "products[i].deleted"] set name [CkJsonObject_stringOf $jResp "products[i].name"] set unit_multiplier [CkJsonObject_IntOf $jResp "products[i].unit_multiplier"] set taxonomy_typeId [CkJsonObject_stringOf $jResp "products[i].taxonomy_type.id"] set taxonomy_typeName [CkJsonObject_stringOf $jResp "products[i].taxonomy_type.name"] set created_at [CkJsonObject_stringOf $jResp "products[i].created_at"] set updated_at [CkJsonObject_stringOf $jResp "products[i].updated_at"] set j 0 set count_j [CkJsonObject_SizeOfArray $jResp "products[i].options"] while {$j < $count_j} { CkJsonObject_put_J $jResp $j set j [expr $j + 1] } set i [expr $i + 1] } delete_CkHttp $http delete_CkJsonObject $queryParams delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.