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) Shippo List All OrdersDemonstrates how to list all orders created by sending a GET request to the orders endpoint. For more information, see https://goshippo.com/docs/orders/
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 https://api.goshippo.com/orders/ \ # -H "Authorization: ShippoToken <API_Token>" CkHttp_SetRequestHeader $http "Authorization" "ShippoToken <API_Token>" set sbResponseBody [new_CkStringBuilder] set success [CkHttp_QuickGetSb $http "https://api.goshippo.com/orders/" $sbResponseBody] if {$success == 0} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkStringBuilder $sbResponseBody exit } set jResp [new_CkJsonObject] CkJsonObject_LoadSb $jResp $sbResponseBody CkJsonObject_put_EmitCompact $jResp 0 puts "Response Body:" puts [CkJsonObject_emit $jResp] set respStatusCode [CkHttp_get_LastStatus $http] puts "Response Status Code = $respStatusCode" if {$respStatusCode >= 400} then { puts "Response Header:" puts [CkHttp_lastHeader $http] puts "Failed." delete_CkHttp $http delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp exit } # Sample JSON response: # (Sample code for parsing the JSON response is shown below) # { # "count": 1382, # "next": "https://api.goshippo.com/orders/?page=2", # "previous": null, # "results": [ # { # "object_id": "4f2bc588e4e5446cb3f9fdb7cd5e190b", # "object_owner": "shippotle@goshippo.com", # "order_number": "#1068", # "order_status": "PAID", # "placed_at": "2016-09-23T01:28:12Z", # "to_address": { # "object_created": "2016-09-23T01:38:56Z", # "object_updated": "2016-09-23T01:38:56Z", # "object_id": "d799c2679e644279b59fe661ac8fa488", # "object_owner": "shippotle@goshippo.com", # "is_complete": true, # "validation_results": {}, # "name": "Mr Hippo", # "company": "Shippo", # "street1": "215 Clayton St.", # "street2": "", # "city": "San Francisco", # "state": "CA", # "zip": "94117", # "country": "US", # "phone": "15553419393", # "email": "shippotle@goshippo.com", # "is_residential": null, # "metadata": "" # }, # "from_address": null, # "line_items": [ # { # "object_id": "abf7d5675d744b6ea9fdb6f796b28f28", # "title": "Hippo Magazines", # "variant_title": "", # "sku": "HM-123", # "quantity": 1, # "total_price": "12.10", # "currency": "USD", # "weight": "0.40", # "weight_unit": "lb", # "manufacture_country": null, # "max_ship_time": null, # "max_delivery_time": null, # "description": null # } # ], # "shipping_cost": "12.83", # "shipping_cost_currency": "USD", # "shipping_method": "USPS First Class Package", # "shop_app": "Shippo", # "subtotal_price": "12.10", # "total_price": "24.93", # "total_tax": "0.00", # "currency": "USD", # "transactions": [ # ], # "weight": "0.40", # "weight_unit": "lb", # "notes": null # }, # ... # ] # } # 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 count [CkJsonObject_IntOf $jResp "count"] set next [CkJsonObject_stringOf $jResp "next"] set previous [CkJsonObject_stringOf $jResp "previous"] set i 0 set count_i [CkJsonObject_SizeOfArray $jResp "results"] while {$i < $count_i} { CkJsonObject_put_I $jResp $i set intVal [CkJsonObject_IntOf $jResp "results[i]"] set j 0 set count_j [CkJsonObject_SizeOfArray $jResp "results[i].line_items"] while {$j < $count_j} { CkJsonObject_put_J $jResp $j set object_id [CkJsonObject_stringOf $jResp "results[i].line_items[j].object_id"] set title [CkJsonObject_stringOf $jResp "results[i].line_items[j].title"] set variant_title [CkJsonObject_stringOf $jResp "results[i].line_items[j].variant_title"] set sku [CkJsonObject_stringOf $jResp "results[i].line_items[j].sku"] set quantity [CkJsonObject_IntOf $jResp "results[i].line_items[j].quantity"] set total_price [CkJsonObject_stringOf $jResp "results[i].line_items[j].total_price"] set currency [CkJsonObject_stringOf $jResp "results[i].line_items[j].currency"] set weight [CkJsonObject_stringOf $jResp "results[i].line_items[j].weight"] set weight_unit [CkJsonObject_stringOf $jResp "results[i].line_items[j].weight_unit"] set manufacture_country [CkJsonObject_stringOf $jResp "results[i].line_items[j].manufacture_country"] set max_ship_time [CkJsonObject_stringOf $jResp "results[i].line_items[j].max_ship_time"] set max_delivery_time [CkJsonObject_stringOf $jResp "results[i].line_items[j].max_delivery_time"] set description [CkJsonObject_stringOf $jResp "results[i].line_items[j].description"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $jResp "results[i].transactions"] while {$j < $count_j} { CkJsonObject_put_J $jResp $j set j [expr $j + 1] } set i [expr $i + 1] } delete_CkHttp $http delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.