DataFlex
DataFlex
Add order to a ShippingEasy account
See more HTTP Misc Examples
Adds an order to a ShippingEasy account (calls the ShippingEasy REST API).Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Variant vJson
Handle hoJson
String sStoreApiKey
String sApiKey
String sApiSecret
Variant vSbSigStr
Handle hoSbSigStr
Handle hoDt
Handle hoCrypt
Handle hoSbSignature
Handle hoSbUrl
Handle hoHttp
String sUrl
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Move False To iSuccess
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// 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.
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "order.external_order_identifier" "ABC-100" To iSuccess
Get ComUpdateString Of hoJson "order.ordered_at" "2014-01-16 14:37:56 -0600" To iSuccess
Get ComUpdateString Of hoJson "order.order_status" "awaiting_shipment" To iSuccess
Get ComUpdateString Of hoJson "order.subtotal_including_tax" "10.00" To iSuccess
Get ComUpdateString Of hoJson "order.total_including_tax" "10.00" To iSuccess
Get ComUpdateString Of hoJson "order.total_excluding_tax" "10.00" To iSuccess
Get ComUpdateString Of hoJson "order.discount_amount" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.coupon_discount" "1.00" To iSuccess
Get ComUpdateString Of hoJson "order.subtotal_including_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.subtotal_excluding_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.subtotal_excluding_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.subtotal_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.total_tax" "0" To iSuccess
Get ComUpdateString Of hoJson "order.base_shipping_cost" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.shipping_cost_including_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.shipping_cost_excluding_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.shipping_cost_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.base_handling_cost" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.handling_cost_excluding_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.handling_cost_including_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.handling_cost_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.base_wrapping_cost" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.wrapping_cost_excluding_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.wrapping_cost_including_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.wrapping_cost_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.notes" "Please send promptly." To iSuccess
Get ComUpdateString Of hoJson "order.billing_company" "Acme Inc." To iSuccess
Get ComUpdateString Of hoJson "order.billing_first_name" "Fred" To iSuccess
Get ComUpdateString Of hoJson "order.billing_last_name" "Jones" To iSuccess
Get ComUpdateString Of hoJson "order.billing_address" "1234 Street" To iSuccess
Get ComUpdateString Of hoJson "order.billing_address2" "Suite 100" To iSuccess
Get ComUpdateString Of hoJson "order.billing_city" "Austin" To iSuccess
Get ComUpdateString Of hoJson "order.billing_state" "TX" To iSuccess
Get ComUpdateString Of hoJson "order.billing_postal_code" "78701" To iSuccess
Get ComUpdateString Of hoJson "order.billing_country" "USA" To iSuccess
Get ComUpdateString Of hoJson "order.billing_phone_number" "512-123-1234" To iSuccess
Get ComUpdateString Of hoJson "order.billing_email" "test@test.com" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].first_name" "Colin" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].last_name" "Homenick" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].company" "Wintheiser-Hickle" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].email" "charles.crona@okeefe.org" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].phone_number" "637-481-6505" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].residential" "true" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].address" "21937 Adelbert Springs" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].address2" "" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].province" "" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].state" "CT" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].city" "Terryfurt" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].postal_code" "93322" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].postal_code_plus_4" "1234" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].country" "Andorra" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].shipping_method" "Ground" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].base_cost" "10.00" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].cost_excluding_tax" "10.00" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].cost_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].base_handling_cost" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].handling_cost_excluding_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].handling_cost_including_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].handling_cost_tax" "0.00" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].shipping_zone_id" "123" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].shipping_zone_name" "XYZ" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].items_total" "1" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].items_shipped" "0" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].line_items[0].item_name" "Pencil Holder" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].line_items[0].sku" "9876543" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].line_items[0].bin_picking_number" "7" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].line_items[0].unit_price" "1.30" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].line_items[0].total_excluding_tax" "1.30" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].line_items[0].weight_in_ounces" "10" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].line_items[0].product_options.pa_size" "large" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].line_items[0].product_options.Colour" "Blue" To iSuccess
Get ComUpdateString Of hoJson "order.recipients[0].line_items[0].quantity" "1" To iSuccess
// Replace these values with your actual apiKey and apiSecret.
// (These are not valid values..)
Move "569dc30d267f2c4d1f85f9920b2bf9f4" To sStoreApiKey
Move "f9a7c8ebdfd34beaf260d9b0296c7059" To sApiKey
Move "d3e9f8737d7196b1271a725f89e2156672bc1d900a25e6e0c1364e2f7a20f605" To sApiSecret
// 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
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbSigStr
If (Not(IsComObjectCreated(hoSbSigStr))) Begin
Send CreateComObject of hoSbSigStr
End
Get ComAppend Of hoSbSigStr "POST&/api/stores/" To iSuccess
Get ComAppend Of hoSbSigStr sStoreApiKey To iSuccess
Get ComAppend Of hoSbSigStr "/orders&" To iSuccess
Get ComAppend Of hoSbSigStr "api_key=" To iSuccess
Get ComAppend Of hoSbSigStr sApiKey To iSuccess
Get ComAppend Of hoSbSigStr "&api_timestamp=" To iSuccess
Get Create (RefClass(cComCkDateTime)) To hoDt
If (Not(IsComObjectCreated(hoDt))) Begin
Send CreateComObject of hoDt
End
Get ComSetFromCurrentSystemTime Of hoDt To iSuccess
Get ComGetAsUnixTimeStr Of hoDt False To sTemp1
Get ComAppend Of hoSbSigStr sTemp1 To iSuccess
Get ComAppend Of hoSbSigStr "&" To iSuccess
Set ComEmitCompact Of hoJson To True
Get pvComObject of hoSbSigStr to vSbSigStr
Get ComEmitSb Of hoJson vSbSigStr To iSuccess
// Calculate the HMAC-SHA256 of the API Signature String using the API Secret as the HMAC key.
Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt
If (Not(IsComObjectCreated(hoCrypt))) Begin
Send CreateComObject of hoCrypt
End
Set ComMacAlgorithm Of hoCrypt To "hmac"
Set ComEncodingMode Of hoCrypt To "hex"
Get ComSetMacKeyString Of hoCrypt sApiSecret To iSuccess
Set ComHashAlgorithm Of hoCrypt To "sha256"
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbSignature
If (Not(IsComObjectCreated(hoSbSignature))) Begin
Send CreateComObject of hoSbSignature
End
Get ComMacStringENC Of hoCrypt (ComGetAsString(hoSbSigStr)) To sTemp1
Get ComAppend Of hoSbSignature sTemp1 To iSuccess
Get ComToLowercase Of hoSbSignature To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbUrl
If (Not(IsComObjectCreated(hoSbUrl))) Begin
Send CreateComObject of hoSbUrl
End
Get ComAppend Of hoSbUrl "https://app.shippingeasy.com/api/stores/" To iSuccess
Get ComAppend Of hoSbUrl sStoreApiKey To iSuccess
Get ComAppend Of hoSbUrl "/orders?" To iSuccess
Get ComAppend Of hoSbUrl "api_key=" To iSuccess
Get ComAppend Of hoSbUrl sApiKey To iSuccess
Get ComAppend Of hoSbUrl "&api_timestamp=" To iSuccess
Get ComGetAsUnixTimeStr Of hoDt False To sTemp1
Get ComAppend Of hoSbUrl sTemp1 To iSuccess
Get ComAppend Of hoSbUrl "&api_signature=" To iSuccess
Get ComGetAsString Of hoSbSignature To sTemp1
Get ComAppend Of hoSbUrl sTemp1 To iSuccess
// 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"
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComSessionLogFilename Of hoHttp To "qa_output/shippingEasy.txt"
Get ComGetAsString Of hoSbUrl To sUrl
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoJson to vJson
Get pvComObject of hoResp to vResp
Get ComHttpJson Of hoHttp "POST" sUrl vJson "application/json" vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln "response status code = " iTemp1
Showln "response body:"
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
End_Procedure