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++) Add order to a ShippingEasy accountAdds an order to a ShippingEasy account (calls the ShippingEasy REST API).
#include <CkJsonObjectW.h> #include <CkStringBuilderW.h> #include <CkDateTimeW.h> #include <CkCrypt2W.h> #include <CkHttpW.h> #include <CkHttpResponseW.h> void ChilkatSample(void) { // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. bool success; // First create the JSON for the order. // See https://shippingeasy.readme.io/v1.0/docs/creating-a-signature // for sample JSON. // You may use the online tool at https://tools.chilkat.io/Default.cshtml to // generate the following code by pasting sample JSON into the tool. CkJsonObjectW json; json.UpdateString(L"order.external_order_identifier",L"ABC-100"); json.UpdateString(L"order.ordered_at",L"2014-01-16 14:37:56 -0600"); json.UpdateString(L"order.order_status",L"awaiting_shipment"); json.UpdateString(L"order.subtotal_including_tax",L"10.00"); json.UpdateString(L"order.total_including_tax",L"10.00"); json.UpdateString(L"order.total_excluding_tax",L"10.00"); json.UpdateString(L"order.discount_amount",L"0.00"); json.UpdateString(L"order.coupon_discount",L"1.00"); json.UpdateString(L"order.subtotal_including_tax",L"0.00"); json.UpdateString(L"order.subtotal_excluding_tax",L"0.00"); json.UpdateString(L"order.subtotal_excluding_tax",L"0.00"); json.UpdateString(L"order.subtotal_tax",L"0.00"); json.UpdateString(L"order.total_tax",L"0"); json.UpdateString(L"order.base_shipping_cost",L"0.00"); json.UpdateString(L"order.shipping_cost_including_tax",L"0.00"); json.UpdateString(L"order.shipping_cost_excluding_tax",L"0.00"); json.UpdateString(L"order.shipping_cost_tax",L"0.00"); json.UpdateString(L"order.base_handling_cost",L"0.00"); json.UpdateString(L"order.handling_cost_excluding_tax",L"0.00"); json.UpdateString(L"order.handling_cost_including_tax",L"0.00"); json.UpdateString(L"order.handling_cost_tax",L"0.00"); json.UpdateString(L"order.base_wrapping_cost",L"0.00"); json.UpdateString(L"order.wrapping_cost_excluding_tax",L"0.00"); json.UpdateString(L"order.wrapping_cost_including_tax",L"0.00"); json.UpdateString(L"order.wrapping_cost_tax",L"0.00"); json.UpdateString(L"order.notes",L"Please send promptly."); json.UpdateString(L"order.billing_company",L"Acme Inc."); json.UpdateString(L"order.billing_first_name",L"Fred"); json.UpdateString(L"order.billing_last_name",L"Jones"); json.UpdateString(L"order.billing_address",L"1234 Street"); json.UpdateString(L"order.billing_address2",L"Suite 100"); json.UpdateString(L"order.billing_city",L"Austin"); json.UpdateString(L"order.billing_state",L"TX"); json.UpdateString(L"order.billing_postal_code",L"78701"); json.UpdateString(L"order.billing_country",L"USA"); json.UpdateString(L"order.billing_phone_number",L"512-123-1234"); json.UpdateString(L"order.billing_email",L"test@test.com"); json.UpdateString(L"order.recipients[0].first_name",L"Colin"); json.UpdateString(L"order.recipients[0].last_name",L"Homenick"); json.UpdateString(L"order.recipients[0].company",L"Wintheiser-Hickle"); json.UpdateString(L"order.recipients[0].email",L"charles.crona@okeefe.org"); json.UpdateString(L"order.recipients[0].phone_number",L"637-481-6505"); json.UpdateString(L"order.recipients[0].residential",L"true"); json.UpdateString(L"order.recipients[0].address",L"21937 Adelbert Springs"); json.UpdateString(L"order.recipients[0].address2",L""); json.UpdateString(L"order.recipients[0].province",L""); json.UpdateString(L"order.recipients[0].state",L"CT"); json.UpdateString(L"order.recipients[0].city",L"Terryfurt"); json.UpdateString(L"order.recipients[0].postal_code",L"93322"); json.UpdateString(L"order.recipients[0].postal_code_plus_4",L"1234"); json.UpdateString(L"order.recipients[0].country",L"Andorra"); json.UpdateString(L"order.recipients[0].shipping_method",L"Ground"); json.UpdateString(L"order.recipients[0].base_cost",L"10.00"); json.UpdateString(L"order.recipients[0].cost_excluding_tax",L"10.00"); json.UpdateString(L"order.recipients[0].cost_tax",L"0.00"); json.UpdateString(L"order.recipients[0].base_handling_cost",L"0.00"); json.UpdateString(L"order.recipients[0].handling_cost_excluding_tax",L"0.00"); json.UpdateString(L"order.recipients[0].handling_cost_including_tax",L"0.00"); json.UpdateString(L"order.recipients[0].handling_cost_tax",L"0.00"); json.UpdateString(L"order.recipients[0].shipping_zone_id",L"123"); json.UpdateString(L"order.recipients[0].shipping_zone_name",L"XYZ"); json.UpdateString(L"order.recipients[0].items_total",L"1"); json.UpdateString(L"order.recipients[0].items_shipped",L"0"); json.UpdateString(L"order.recipients[0].line_items[0].item_name",L"Pencil Holder"); json.UpdateString(L"order.recipients[0].line_items[0].sku",L"9876543"); json.UpdateString(L"order.recipients[0].line_items[0].bin_picking_number",L"7"); json.UpdateString(L"order.recipients[0].line_items[0].unit_price",L"1.30"); json.UpdateString(L"order.recipients[0].line_items[0].total_excluding_tax",L"1.30"); json.UpdateString(L"order.recipients[0].line_items[0].weight_in_ounces",L"10"); json.UpdateString(L"order.recipients[0].line_items[0].product_options.pa_size",L"large"); json.UpdateString(L"order.recipients[0].line_items[0].product_options.Colour",L"Blue"); json.UpdateString(L"order.recipients[0].line_items[0].quantity",L"1"); // Replace these values with your actual apiKey and apiSecret. // (These are not valid values..) const wchar_t *storeApiKey = L"569dc30d267f2c4d1f85f9920b2bf9f4"; const wchar_t *apiKey = L"f9a7c8ebdfd34beaf260d9b0296c7059"; const wchar_t *apiSecret = L"d3e9f8737d7196b1271a725f89e2156672bc1d900a25e6e0c1364e2f7a20f605"; // Our request will be sent to: // https://app.shippingeasy.com/api/stores/:store_api_key/orders // The path part of this request is: /api/stores/:store_api_key/orders // See https://shippingeasy.readme.io/v1.0/docs/authentication-signing-requests CkStringBuilderW sbSigStr; sbSigStr.Append(L"POST&/api/stores/"); sbSigStr.Append(storeApiKey); sbSigStr.Append(L"/orders&"); sbSigStr.Append(L"api_key="); sbSigStr.Append(apiKey); sbSigStr.Append(L"&api_timestamp="); CkDateTimeW dt; dt.SetFromCurrentSystemTime(); sbSigStr.Append(dt.getAsUnixTimeStr(false)); sbSigStr.Append(L"&"); json.put_EmitCompact(true); json.EmitSb(sbSigStr); // Calculate the HMAC-SHA256 of the API Signature String using the API Secret as the HMAC key. CkCrypt2W crypt; crypt.put_MacAlgorithm(L"hmac"); crypt.put_EncodingMode(L"hex"); crypt.SetMacKeyString(apiSecret); crypt.put_HashAlgorithm(L"sha256"); CkStringBuilderW sbSignature; sbSignature.Append(crypt.macStringENC(sbSigStr.getAsString())); sbSignature.ToLowercase(); CkStringBuilderW sbUrl; sbUrl.Append(L"https://app.shippingeasy.com/api/stores/"); sbUrl.Append(storeApiKey); sbUrl.Append(L"/orders?"); sbUrl.Append(L"api_key="); sbUrl.Append(apiKey); sbUrl.Append(L"&api_timestamp="); sbUrl.Append(dt.getAsUnixTimeStr(false)); sbUrl.Append(L"&api_signature="); sbUrl.Append(sbSignature.getAsString()); // Send a POST equivalent the following curl request: // curl -H "Content-Type: application/json" --data @body.json "https://app.shippingeasy.com/api/stores/27aa472e16faa83dd13b7758d31974ed/orders? // api_key=f9a7c8ebdfd34beaf260d9b0296c7059& // api_timestamp=1401803554& // api_signature=c65f43beed46e581939898a78acd10064cfa146845e97885ec02124d7ad648e4" CkHttpW http; http.put_SessionLogFilename(L"qa_output/shippingEasy.txt"); CkHttpResponseW *resp = http.PostJson2(sbUrl.getAsString(),L"application/json",json.emit()); if (http.get_LastMethodSuccess() != true) { wprintf(L"%s\n",http.lastErrorText()); return; } wprintf(L"response status code = %d\n",resp->get_StatusCode()); wprintf(L"response body:\n"); wprintf(L"%s\n",resp->bodyStr()); delete resp; } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.