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 Create an OrderDemonstrates how to create an order with all the information about your order by sending a POST request to the orders endpoint. For more information, see https://goshippo.com/docs/orders/
#include <CkHttpW.h> #include <CkJsonObjectW.h> #include <CkHttpResponseW.h> #include <CkStringBuilderW.h> void ChilkatSample(void) { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttpW http; bool success; // Implements the following CURL command: // curl https://api.goshippo.com/orders/ \ // -H "Authorization: ShippoToken <API_Token>" \ // -H "Content-Type: application/json" \ // -d '{ // "to_address": { // "city": "San Francisco", // "company": "Shippo", // "country": "US", // "email": "shippotle@goshippo.com", // "name": "Mr Hippo", // "phone": "15553419393", // "state": "CA", // "street1": "215 Clayton St.", // "zip": "94117" // }, // "line_items": [ // { // "quantity": 1, // "sku": "HM-123", // "title": "Hippo Magazines", // "total_price": "12.10", // "currency": "USD", // "weight": "0.40", // "weight_unit": "lb" // } // ], // "placed_at": "2016-09-23T01:28:12Z", // "order_number": "#1068", // "order_status": "PAID", // "shipping_cost": "12.83", // "shipping_cost_currency": "USD", // "shipping_method": "USPS First Class Package", // "subtotal_price": "12.10", // "total_price": "24.93", // "total_tax": "0.00", // "currency": "USD", // "weight": "0.40", // "weight_unit": "lb" // }' // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "to_address": { // "city": "San Francisco", // "company": "Shippo", // "country": "US", // "email": "shippotle@goshippo.com", // "name": "Mr Hippo", // "phone": "15553419393", // "state": "CA", // "street1": "215 Clayton St.", // "zip": "94117" // }, // "line_items": [ // { // "quantity": 1, // "sku": "HM-123", // "title": "Hippo Magazines", // "total_price": "12.10", // "currency": "USD", // "weight": "0.40", // "weight_unit": "lb" // } // ], // "placed_at": "2016-09-23T01:28:12Z", // "order_number": "#1068", // "order_status": "PAID", // "shipping_cost": "12.83", // "shipping_cost_currency": "USD", // "shipping_method": "USPS First Class Package", // "subtotal_price": "12.10", // "total_price": "24.93", // "total_tax": "0.00", // "currency": "USD", // "weight": "0.40", // "weight_unit": "lb" // } CkJsonObjectW json; json.UpdateString(L"to_address.city",L"San Francisco"); json.UpdateString(L"to_address.company",L"Shippo"); json.UpdateString(L"to_address.country",L"US"); json.UpdateString(L"to_address.email",L"shippotle@goshippo.com"); json.UpdateString(L"to_address.name",L"Mr Hippo"); json.UpdateString(L"to_address.phone",L"15553419393"); json.UpdateString(L"to_address.state",L"CA"); json.UpdateString(L"to_address.street1",L"215 Clayton St."); json.UpdateString(L"to_address.zip",L"94117"); json.UpdateInt(L"line_items[0].quantity",1); json.UpdateString(L"line_items[0].sku",L"HM-123"); json.UpdateString(L"line_items[0].title",L"Hippo Magazines"); json.UpdateString(L"line_items[0].total_price",L"12.10"); json.UpdateString(L"line_items[0].currency",L"USD"); json.UpdateString(L"line_items[0].weight",L"0.40"); json.UpdateString(L"line_items[0].weight_unit",L"lb"); json.UpdateString(L"placed_at",L"2016-09-23T01:28:12Z"); json.UpdateString(L"order_number",L"#1068"); json.UpdateString(L"order_status",L"PAID"); json.UpdateString(L"shipping_cost",L"12.83"); json.UpdateString(L"shipping_cost_currency",L"USD"); json.UpdateString(L"shipping_method",L"USPS First Class Package"); json.UpdateString(L"subtotal_price",L"12.10"); json.UpdateString(L"total_price",L"24.93"); json.UpdateString(L"total_tax",L"0.00"); json.UpdateString(L"currency",L"USD"); json.UpdateString(L"weight",L"0.40"); json.UpdateString(L"weight_unit",L"lb"); http.SetRequestHeader(L"Authorization",L"ShippoToken <API_Token>"); http.SetRequestHeader(L"Content-Type",L"application/json"); CkHttpResponseW *resp = http.PostJson3(L"https://api.goshippo.com/orders/",L"application/json",json); if (http.get_LastMethodSuccess() == false) { wprintf(L"%s\n",http.lastErrorText()); return; } CkStringBuilderW sbResponseBody; resp->GetBodySb(sbResponseBody); CkJsonObjectW jResp; jResp.LoadSb(sbResponseBody); jResp.put_EmitCompact(false); wprintf(L"Response Body:\n"); wprintf(L"%s\n",jResp.emit()); int respStatusCode = resp->get_StatusCode(); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",resp->header()); wprintf(L"Failed.\n"); delete resp; return; } delete resp; // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // {} // 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. } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.