Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Tcl Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Tcl) Add order to a ShippingEasy account

Adds an order to a ShippingEasy account (calls the ShippingEasy REST API).

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

#  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.
set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "order.external_order_identifier" "ABC-100"
CkJsonObject_UpdateString $json "order.ordered_at" "2014-01-16 14:37:56 -0600"
CkJsonObject_UpdateString $json "order.order_status" "awaiting_shipment"
CkJsonObject_UpdateString $json "order.subtotal_including_tax" "10.00"
CkJsonObject_UpdateString $json "order.total_including_tax" "10.00"
CkJsonObject_UpdateString $json "order.total_excluding_tax" "10.00"
CkJsonObject_UpdateString $json "order.discount_amount" "0.00"
CkJsonObject_UpdateString $json "order.coupon_discount" "1.00"
CkJsonObject_UpdateString $json "order.subtotal_including_tax" "0.00"
CkJsonObject_UpdateString $json "order.subtotal_excluding_tax" "0.00"
CkJsonObject_UpdateString $json "order.subtotal_excluding_tax" "0.00"
CkJsonObject_UpdateString $json "order.subtotal_tax" "0.00"
CkJsonObject_UpdateString $json "order.total_tax" "0"
CkJsonObject_UpdateString $json "order.base_shipping_cost" "0.00"
CkJsonObject_UpdateString $json "order.shipping_cost_including_tax" "0.00"
CkJsonObject_UpdateString $json "order.shipping_cost_excluding_tax" "0.00"
CkJsonObject_UpdateString $json "order.shipping_cost_tax" "0.00"
CkJsonObject_UpdateString $json "order.base_handling_cost" "0.00"
CkJsonObject_UpdateString $json "order.handling_cost_excluding_tax" "0.00"
CkJsonObject_UpdateString $json "order.handling_cost_including_tax" "0.00"
CkJsonObject_UpdateString $json "order.handling_cost_tax" "0.00"
CkJsonObject_UpdateString $json "order.base_wrapping_cost" "0.00"
CkJsonObject_UpdateString $json "order.wrapping_cost_excluding_tax" "0.00"
CkJsonObject_UpdateString $json "order.wrapping_cost_including_tax" "0.00"
CkJsonObject_UpdateString $json "order.wrapping_cost_tax" "0.00"
CkJsonObject_UpdateString $json "order.notes" "Please send promptly."
CkJsonObject_UpdateString $json "order.billing_company" "Acme Inc."
CkJsonObject_UpdateString $json "order.billing_first_name" "Fred"
CkJsonObject_UpdateString $json "order.billing_last_name" "Jones"
CkJsonObject_UpdateString $json "order.billing_address" "1234 Street"
CkJsonObject_UpdateString $json "order.billing_address2" "Suite 100"
CkJsonObject_UpdateString $json "order.billing_city" "Austin"
CkJsonObject_UpdateString $json "order.billing_state" "TX"
CkJsonObject_UpdateString $json "order.billing_postal_code" "78701"
CkJsonObject_UpdateString $json "order.billing_country" "USA"
CkJsonObject_UpdateString $json "order.billing_phone_number" "512-123-1234"
CkJsonObject_UpdateString $json "order.billing_email" "test@test.com"
CkJsonObject_UpdateString $json "order.recipients[0].first_name" "Colin"
CkJsonObject_UpdateString $json "order.recipients[0].last_name" "Homenick"
CkJsonObject_UpdateString $json "order.recipients[0].company" "Wintheiser-Hickle"
CkJsonObject_UpdateString $json "order.recipients[0].email" "charles.crona@okeefe.org"
CkJsonObject_UpdateString $json "order.recipients[0].phone_number" "637-481-6505"
CkJsonObject_UpdateString $json "order.recipients[0].residential" "true"
CkJsonObject_UpdateString $json "order.recipients[0].address" "21937 Adelbert Springs"
CkJsonObject_UpdateString $json "order.recipients[0].address2" ""
CkJsonObject_UpdateString $json "order.recipients[0].province" ""
CkJsonObject_UpdateString $json "order.recipients[0].state" "CT"
CkJsonObject_UpdateString $json "order.recipients[0].city" "Terryfurt"
CkJsonObject_UpdateString $json "order.recipients[0].postal_code" "93322"
CkJsonObject_UpdateString $json "order.recipients[0].postal_code_plus_4" "1234"
CkJsonObject_UpdateString $json "order.recipients[0].country" "Andorra"
CkJsonObject_UpdateString $json "order.recipients[0].shipping_method" "Ground"
CkJsonObject_UpdateString $json "order.recipients[0].base_cost" "10.00"
CkJsonObject_UpdateString $json "order.recipients[0].cost_excluding_tax" "10.00"
CkJsonObject_UpdateString $json "order.recipients[0].cost_tax" "0.00"
CkJsonObject_UpdateString $json "order.recipients[0].base_handling_cost" "0.00"
CkJsonObject_UpdateString $json "order.recipients[0].handling_cost_excluding_tax" "0.00"
CkJsonObject_UpdateString $json "order.recipients[0].handling_cost_including_tax" "0.00"
CkJsonObject_UpdateString $json "order.recipients[0].handling_cost_tax" "0.00"
CkJsonObject_UpdateString $json "order.recipients[0].shipping_zone_id" "123"
CkJsonObject_UpdateString $json "order.recipients[0].shipping_zone_name" "XYZ"
CkJsonObject_UpdateString $json "order.recipients[0].items_total" "1"
CkJsonObject_UpdateString $json "order.recipients[0].items_shipped" "0"
CkJsonObject_UpdateString $json "order.recipients[0].line_items[0].item_name" "Pencil Holder"
CkJsonObject_UpdateString $json "order.recipients[0].line_items[0].sku" "9876543"
CkJsonObject_UpdateString $json "order.recipients[0].line_items[0].bin_picking_number" "7"
CkJsonObject_UpdateString $json "order.recipients[0].line_items[0].unit_price" "1.30"
CkJsonObject_UpdateString $json "order.recipients[0].line_items[0].total_excluding_tax" "1.30"
CkJsonObject_UpdateString $json "order.recipients[0].line_items[0].weight_in_ounces" "10"
CkJsonObject_UpdateString $json "order.recipients[0].line_items[0].product_options.pa_size" "large"
CkJsonObject_UpdateString $json "order.recipients[0].line_items[0].product_options.Colour" "Blue"
CkJsonObject_UpdateString $json "order.recipients[0].line_items[0].quantity" "1"

#  Replace these values with your actual apiKey and apiSecret.
#  (These are not valid values..)
set storeApiKey "569dc30d267f2c4d1f85f9920b2bf9f4"
set apiKey "f9a7c8ebdfd34beaf260d9b0296c7059"
set apiSecret "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
set sbSigStr [new_CkStringBuilder]

CkStringBuilder_Append $sbSigStr "POST&/api/stores/"
CkStringBuilder_Append $sbSigStr $storeApiKey
CkStringBuilder_Append $sbSigStr "/orders&"
CkStringBuilder_Append $sbSigStr "api_key="
CkStringBuilder_Append $sbSigStr $apiKey
CkStringBuilder_Append $sbSigStr "&api_timestamp="

set dt [new_CkDateTime]

CkDateTime_SetFromCurrentSystemTime $dt
CkStringBuilder_Append $sbSigStr [CkDateTime_getAsUnixTimeStr $dt 0]
CkStringBuilder_Append $sbSigStr "&"

CkJsonObject_put_EmitCompact $json 1
CkJsonObject_EmitSb $json $sbSigStr

#  Calculate the HMAC-SHA256 of the API Signature String using the API Secret as the HMAC key.
set crypt [new_CkCrypt2]

CkCrypt2_put_MacAlgorithm $crypt "hmac"
CkCrypt2_put_EncodingMode $crypt "hex"
CkCrypt2_SetMacKeyString $crypt $apiSecret
CkCrypt2_put_HashAlgorithm $crypt "sha256"

set sbSignature [new_CkStringBuilder]

CkStringBuilder_Append $sbSignature [CkCrypt2_macStringENC $crypt [CkStringBuilder_getAsString $sbSigStr]]
CkStringBuilder_ToLowercase $sbSignature

set sbUrl [new_CkStringBuilder]

CkStringBuilder_Append $sbUrl "https://app.shippingeasy.com/api/stores/"
CkStringBuilder_Append $sbUrl $storeApiKey
CkStringBuilder_Append $sbUrl "/orders?"
CkStringBuilder_Append $sbUrl "api_key="
CkStringBuilder_Append $sbUrl $apiKey
CkStringBuilder_Append $sbUrl "&api_timestamp="
CkStringBuilder_Append $sbUrl [CkDateTime_getAsUnixTimeStr $dt 0]
CkStringBuilder_Append $sbUrl "&api_signature="
CkStringBuilder_Append $sbUrl [CkStringBuilder_getAsString $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"

set http [new_CkHttp]

CkHttp_put_SessionLogFilename $http "qa_output/shippingEasy.txt"
# resp is a CkHttpResponse
set resp [CkHttp_PostJson2 $http [CkStringBuilder_getAsString $sbUrl] "application/json" [CkJsonObject_emit $json]]
if {[expr [CkHttp_get_LastMethodSuccess $http] != 1]} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbSigStr
    delete_CkDateTime $dt
    delete_CkCrypt2 $crypt
    delete_CkStringBuilder $sbSignature
    delete_CkStringBuilder $sbUrl
    delete_CkHttp $http
    exit
}

puts "response status code = [CkHttpResponse_get_StatusCode $resp]"
puts "response body:"
puts [CkHttpResponse_bodyStr $resp]
delete_CkHttpResponse $resp


delete_CkJsonObject $json
delete_CkStringBuilder $sbSigStr
delete_CkDateTime $dt
delete_CkCrypt2 $crypt
delete_CkStringBuilder $sbSignature
delete_CkStringBuilder $sbUrl
delete_CkHttp $http

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.