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

Swift 3/4 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

 

 

 

(Swift 3/4) Add order to a ShippingEasy account

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

Chilkat Downloads for the Swift Programming Language

MAC OS X (Cocoa) Objective-C/Swift Libs

iOS Objective-C/Swift Libs

func chilkatTest() {
    //  This requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.
    var success: Bool

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

    //  Replace these values with your actual apiKey and apiSecret.
    //  (These are not valid values..)
    var storeApiKey: String? = "569dc30d267f2c4d1f85f9920b2bf9f4"
    var apiKey: String? = "f9a7c8ebdfd34beaf260d9b0296c7059"
    var apiSecret: String? = "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
    let sbSigStr = CkoStringBuilder()!
    sbSigStr.append("POST&/api/stores/")
    sbSigStr.append(storeApiKey)
    sbSigStr.append("/orders&")
    sbSigStr.append("api_key=")
    sbSigStr.append(apiKey)
    sbSigStr.append("&api_timestamp=")

    let dt = CkoDateTime()!
    dt.setFromCurrentSystemTime()
    sbSigStr.append(dt.getAsUnixTimeStr(false))
    sbSigStr.append("&")

    json.emitCompact = true
    json.emitSb(sbSigStr)

    //  Calculate the HMAC-SHA256 of the API Signature String using the API Secret as the HMAC key.
    let crypt = CkoCrypt2()!
    crypt.macAlgorithm = "hmac"
    crypt.encodingMode = "hex"
    crypt.setMacKeyString(apiSecret)
    crypt.hashAlgorithm = "sha256"

    let sbSignature = CkoStringBuilder()!
    sbSignature.append(crypt.macStringENC(sbSigStr.getAsString()))
    sbSignature.toLowercase()

    let sbUrl = CkoStringBuilder()!
    sbUrl.append("https://app.shippingeasy.com/api/stores/")
    sbUrl.append(storeApiKey)
    sbUrl.append("/orders?")
    sbUrl.append("api_key=")
    sbUrl.append(apiKey)
    sbUrl.append("&api_timestamp=")
    sbUrl.append(dt.getAsUnixTimeStr(false))
    sbUrl.append("&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"

    let http = CkoHttp()!
    http.sessionLogFilename = "qa_output/shippingEasy.txt"
    var resp: CkoHttpResponse? = http.postJson2(sbUrl.getAsString(), contentType: "application/json", jsonText: json.emit())
    if http.lastMethodSuccess != true {
        print("\(http.lastErrorText!)")
        return
    }

    print("response status code = \(resp!.statusCode.intValue)")
    print("response body:")
    print("\(resp!.bodyStr!)")
    resp = nil

}

 

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