Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) 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 <CkHttp.h> #include <CkStringBuilder.h> #include <CkJsonObject.h> void ChilkatSample(void) { CkString strOut; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttp http; bool success; // Implements the following CURL command: // curl https://api.goshippo.com/orders/ \ // -H "Authorization: ShippoToken <API_Token>" http.SetRequestHeader("Authorization","ShippoToken <API_Token>"); CkStringBuilder sbResponseBody; success = http.QuickGetSb("https://api.goshippo.com/orders/",sbResponseBody); if (success == false) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } CkJsonObject jResp; jResp.LoadSb(sbResponseBody); jResp.put_EmitCompact(false); strOut.append("Response Body:"); strOut.append("\r\n"); strOut.append(jResp.emit()); strOut.append("\r\n"); int respStatusCode = http.get_LastStatus(); strOut.append("Response Status Code = "); strOut.appendInt(respStatusCode); strOut.append("\r\n"); if (respStatusCode >= 400) { strOut.append("Response Header:"); strOut.append("\r\n"); strOut.append(http.lastHeader()); strOut.append("\r\n"); strOut.append("Failed."); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); 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. int intVal; int j; int count_j; const char *object_id = 0; const char *title = 0; const char *variant_title = 0; const char *sku = 0; int quantity; const char *total_price = 0; const char *currency = 0; const char *weight = 0; const char *weight_unit = 0; const char *manufacture_country = 0; const char *max_ship_time = 0; const char *max_delivery_time = 0; const char *description = 0; int count = jResp.IntOf("count"); const char *next = jResp.stringOf("next"); const char *previous = jResp.stringOf("previous"); int i = 0; int count_i = jResp.SizeOfArray("results"); while (i < count_i) { jResp.put_I(i); intVal = jResp.IntOf("results[i]"); j = 0; count_j = jResp.SizeOfArray("results[i].line_items"); while (j < count_j) { jResp.put_J(j); object_id = jResp.stringOf("results[i].line_items[j].object_id"); title = jResp.stringOf("results[i].line_items[j].title"); variant_title = jResp.stringOf("results[i].line_items[j].variant_title"); sku = jResp.stringOf("results[i].line_items[j].sku"); quantity = jResp.IntOf("results[i].line_items[j].quantity"); total_price = jResp.stringOf("results[i].line_items[j].total_price"); currency = jResp.stringOf("results[i].line_items[j].currency"); weight = jResp.stringOf("results[i].line_items[j].weight"); weight_unit = jResp.stringOf("results[i].line_items[j].weight_unit"); manufacture_country = jResp.stringOf("results[i].line_items[j].manufacture_country"); max_ship_time = jResp.stringOf("results[i].line_items[j].max_ship_time"); max_delivery_time = jResp.stringOf("results[i].line_items[j].max_delivery_time"); description = jResp.stringOf("results[i].line_items[j].description"); j = j + 1; } j = 0; count_j = jResp.SizeOfArray("results[i].transactions"); while (j < count_j) { jResp.put_J(j); j = j + 1; } i = i + 1; } SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.