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
(PureBasic) Add order to a ShippingEasy accountAdds an order to a ShippingEasy account (calls the ShippingEasy REST API).
IncludeFile "CkJsonObject.pb" IncludeFile "CkDateTime.pb" IncludeFile "CkHttp.pb" IncludeFile "CkCrypt2.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkHttpResponse.pb" Procedure ChilkatExample() ; This requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. success.i ; 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. json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"order.external_order_identifier","ABC-100") CkJsonObject::ckUpdateString(json,"order.ordered_at","2014-01-16 14:37:56 -0600") CkJsonObject::ckUpdateString(json,"order.order_status","awaiting_shipment") CkJsonObject::ckUpdateString(json,"order.subtotal_including_tax","10.00") CkJsonObject::ckUpdateString(json,"order.total_including_tax","10.00") CkJsonObject::ckUpdateString(json,"order.total_excluding_tax","10.00") CkJsonObject::ckUpdateString(json,"order.discount_amount","0.00") CkJsonObject::ckUpdateString(json,"order.coupon_discount","1.00") CkJsonObject::ckUpdateString(json,"order.subtotal_including_tax","0.00") CkJsonObject::ckUpdateString(json,"order.subtotal_excluding_tax","0.00") CkJsonObject::ckUpdateString(json,"order.subtotal_excluding_tax","0.00") CkJsonObject::ckUpdateString(json,"order.subtotal_tax","0.00") CkJsonObject::ckUpdateString(json,"order.total_tax","0") CkJsonObject::ckUpdateString(json,"order.base_shipping_cost","0.00") CkJsonObject::ckUpdateString(json,"order.shipping_cost_including_tax","0.00") CkJsonObject::ckUpdateString(json,"order.shipping_cost_excluding_tax","0.00") CkJsonObject::ckUpdateString(json,"order.shipping_cost_tax","0.00") CkJsonObject::ckUpdateString(json,"order.base_handling_cost","0.00") CkJsonObject::ckUpdateString(json,"order.handling_cost_excluding_tax","0.00") CkJsonObject::ckUpdateString(json,"order.handling_cost_including_tax","0.00") CkJsonObject::ckUpdateString(json,"order.handling_cost_tax","0.00") CkJsonObject::ckUpdateString(json,"order.base_wrapping_cost","0.00") CkJsonObject::ckUpdateString(json,"order.wrapping_cost_excluding_tax","0.00") CkJsonObject::ckUpdateString(json,"order.wrapping_cost_including_tax","0.00") CkJsonObject::ckUpdateString(json,"order.wrapping_cost_tax","0.00") CkJsonObject::ckUpdateString(json,"order.notes","Please send promptly.") CkJsonObject::ckUpdateString(json,"order.billing_company","Acme Inc.") CkJsonObject::ckUpdateString(json,"order.billing_first_name","Fred") CkJsonObject::ckUpdateString(json,"order.billing_last_name","Jones") CkJsonObject::ckUpdateString(json,"order.billing_address","1234 Street") CkJsonObject::ckUpdateString(json,"order.billing_address2","Suite 100") CkJsonObject::ckUpdateString(json,"order.billing_city","Austin") CkJsonObject::ckUpdateString(json,"order.billing_state","TX") CkJsonObject::ckUpdateString(json,"order.billing_postal_code","78701") CkJsonObject::ckUpdateString(json,"order.billing_country","USA") CkJsonObject::ckUpdateString(json,"order.billing_phone_number","512-123-1234") CkJsonObject::ckUpdateString(json,"order.billing_email","test@test.com") CkJsonObject::ckUpdateString(json,"order.recipients[0].first_name","Colin") CkJsonObject::ckUpdateString(json,"order.recipients[0].last_name","Homenick") CkJsonObject::ckUpdateString(json,"order.recipients[0].company","Wintheiser-Hickle") CkJsonObject::ckUpdateString(json,"order.recipients[0].email","charles.crona@okeefe.org") CkJsonObject::ckUpdateString(json,"order.recipients[0].phone_number","637-481-6505") CkJsonObject::ckUpdateString(json,"order.recipients[0].residential","true") CkJsonObject::ckUpdateString(json,"order.recipients[0].address","21937 Adelbert Springs") CkJsonObject::ckUpdateString(json,"order.recipients[0].address2","") CkJsonObject::ckUpdateString(json,"order.recipients[0].province","") CkJsonObject::ckUpdateString(json,"order.recipients[0].state","CT") CkJsonObject::ckUpdateString(json,"order.recipients[0].city","Terryfurt") CkJsonObject::ckUpdateString(json,"order.recipients[0].postal_code","93322") CkJsonObject::ckUpdateString(json,"order.recipients[0].postal_code_plus_4","1234") CkJsonObject::ckUpdateString(json,"order.recipients[0].country","Andorra") CkJsonObject::ckUpdateString(json,"order.recipients[0].shipping_method","Ground") CkJsonObject::ckUpdateString(json,"order.recipients[0].base_cost","10.00") CkJsonObject::ckUpdateString(json,"order.recipients[0].cost_excluding_tax","10.00") CkJsonObject::ckUpdateString(json,"order.recipients[0].cost_tax","0.00") CkJsonObject::ckUpdateString(json,"order.recipients[0].base_handling_cost","0.00") CkJsonObject::ckUpdateString(json,"order.recipients[0].handling_cost_excluding_tax","0.00") CkJsonObject::ckUpdateString(json,"order.recipients[0].handling_cost_including_tax","0.00") CkJsonObject::ckUpdateString(json,"order.recipients[0].handling_cost_tax","0.00") CkJsonObject::ckUpdateString(json,"order.recipients[0].shipping_zone_id","123") CkJsonObject::ckUpdateString(json,"order.recipients[0].shipping_zone_name","XYZ") CkJsonObject::ckUpdateString(json,"order.recipients[0].items_total","1") CkJsonObject::ckUpdateString(json,"order.recipients[0].items_shipped","0") CkJsonObject::ckUpdateString(json,"order.recipients[0].line_items[0].item_name","Pencil Holder") CkJsonObject::ckUpdateString(json,"order.recipients[0].line_items[0].sku","9876543") CkJsonObject::ckUpdateString(json,"order.recipients[0].line_items[0].bin_picking_number","7") CkJsonObject::ckUpdateString(json,"order.recipients[0].line_items[0].unit_price","1.30") CkJsonObject::ckUpdateString(json,"order.recipients[0].line_items[0].total_excluding_tax","1.30") CkJsonObject::ckUpdateString(json,"order.recipients[0].line_items[0].weight_in_ounces","10") CkJsonObject::ckUpdateString(json,"order.recipients[0].line_items[0].product_options.pa_size","large") CkJsonObject::ckUpdateString(json,"order.recipients[0].line_items[0].product_options.Colour","Blue") CkJsonObject::ckUpdateString(json,"order.recipients[0].line_items[0].quantity","1") ; Replace these values with your actual apiKey and apiSecret. ; (These are not valid values..) storeApiKey.s = "569dc30d267f2c4d1f85f9920b2bf9f4" apiKey.s = "f9a7c8ebdfd34beaf260d9b0296c7059" apiSecret.s = "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 sbSigStr.i = CkStringBuilder::ckCreate() If sbSigStr.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbSigStr,"POST&/api/stores/") CkStringBuilder::ckAppend(sbSigStr,storeApiKey) CkStringBuilder::ckAppend(sbSigStr,"/orders&") CkStringBuilder::ckAppend(sbSigStr,"api_key=") CkStringBuilder::ckAppend(sbSigStr,apiKey) CkStringBuilder::ckAppend(sbSigStr,"&api_timestamp=") dt.i = CkDateTime::ckCreate() If dt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkDateTime::ckSetFromCurrentSystemTime(dt) CkStringBuilder::ckAppend(sbSigStr,CkDateTime::ckGetAsUnixTimeStr(dt,0)) CkStringBuilder::ckAppend(sbSigStr,"&") CkJsonObject::setCkEmitCompact(json, 1) CkJsonObject::ckEmitSb(json,sbSigStr) ; Calculate the HMAC-SHA256 of the API Signature String using the API Secret as the HMAC key. crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkCrypt2::setCkMacAlgorithm(crypt, "hmac") CkCrypt2::setCkEncodingMode(crypt, "hex") CkCrypt2::ckSetMacKeyString(crypt,apiSecret) CkCrypt2::setCkHashAlgorithm(crypt, "sha256") sbSignature.i = CkStringBuilder::ckCreate() If sbSignature.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbSignature,CkCrypt2::ckMacStringENC(crypt,CkStringBuilder::ckGetAsString(sbSigStr))) CkStringBuilder::ckToLowercase(sbSignature) sbUrl.i = CkStringBuilder::ckCreate() If sbUrl.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbUrl,"https://app.shippingeasy.com/api/stores/") CkStringBuilder::ckAppend(sbUrl,storeApiKey) CkStringBuilder::ckAppend(sbUrl,"/orders?") CkStringBuilder::ckAppend(sbUrl,"api_key=") CkStringBuilder::ckAppend(sbUrl,apiKey) CkStringBuilder::ckAppend(sbUrl,"&api_timestamp=") CkStringBuilder::ckAppend(sbUrl,CkDateTime::ckGetAsUnixTimeStr(dt,0)) CkStringBuilder::ckAppend(sbUrl,"&api_signature=") CkStringBuilder::ckAppend(sbUrl,CkStringBuilder::ckGetAsString(sbSignature)) ; 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" http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttp::setCkSessionLogFilename(http, "qa_output/shippingEasy.txt") resp.i = CkHttp::ckPostJson2(http,CkStringBuilder::ckGetAsString(sbUrl),"application/json",CkJsonObject::ckEmit(json)) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbSigStr) CkDateTime::ckDispose(dt) CkCrypt2::ckDispose(crypt) CkStringBuilder::ckDispose(sbSignature) CkStringBuilder::ckDispose(sbUrl) CkHttp::ckDispose(http) ProcedureReturn EndIf Debug "response status code = " + Str(CkHttpResponse::ckStatusCode(resp)) Debug "response body:" Debug CkHttpResponse::ckBodyStr(resp) CkHttpResponse::ckDispose(resp) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbSigStr) CkDateTime::ckDispose(dt) CkCrypt2::ckDispose(crypt) CkStringBuilder::ckDispose(sbSignature) CkStringBuilder::ckDispose(sbUrl) CkHttp::ckDispose(http) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.