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
(Unicode C) 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/
#include <C_CkHttpW.h> #include <C_CkStringBuilderW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; int intVal; int j; int count_j; const wchar_t *object_id; const wchar_t *title; const wchar_t *variant_title; const wchar_t *sku; int quantity; const wchar_t *total_price; const wchar_t *currency; const wchar_t *weight; const wchar_t *weight_unit; const wchar_t *manufacture_country; const wchar_t *max_ship_time; const wchar_t *max_delivery_time; const wchar_t *description; int count; const wchar_t *next; const wchar_t *previous; int i; int count_i; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // Implements the following CURL command: // curl https://api.goshippo.com/orders/ \ // -H "Authorization: ShippoToken <API_Token>" CkHttpW_SetRequestHeader(http,L"Authorization",L"ShippoToken <API_Token>"); sbResponseBody = CkStringBuilderW_Create(); success = CkHttpW_QuickGetSb(http,L"https://api.goshippo.com/orders/",sbResponseBody); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); return; } jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpW_getLastStatus(http); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpW_lastHeader(http)); wprintf(L"Failed.\n"); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } // 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 // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. count = CkJsonObjectW_IntOf(jResp,L"count"); next = CkJsonObjectW_stringOf(jResp,L"next"); previous = CkJsonObjectW_stringOf(jResp,L"previous"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"results"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); intVal = CkJsonObjectW_IntOf(jResp,L"results[i]"); j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"results[i].line_items"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); object_id = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].object_id"); title = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].title"); variant_title = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].variant_title"); sku = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].sku"); quantity = CkJsonObjectW_IntOf(jResp,L"results[i].line_items[j].quantity"); total_price = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].total_price"); currency = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].currency"); weight = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].weight"); weight_unit = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].weight_unit"); manufacture_country = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].manufacture_country"); max_ship_time = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].max_ship_time"); max_delivery_time = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].max_delivery_time"); description = CkJsonObjectW_stringOf(jResp,L"results[i].line_items[j].description"); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"results[i].transactions"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); j = j + 1; } i = i + 1; } CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.