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
(Swift 2) Shippo Create Customs DeclarationDemonstrates how to create a customs declaration and send a POST request with the necessary information to the Customs Declarations endpoint. For more information, see https://goshippo.com/docs/international/
func chilkatTest() { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. let http = CkoHttp() var success: Bool // Implements the following CURL command: // curl https://api.goshippo.com/customs/declarations/ \ // -H "Authorization: ShippoToken <API_TOKEN>" \ // -H "Content-Type: application/json" \ // -d '{ // "contents_type": "MERCHANDISE", // "non_delivery_option": "RETURN", // "certify": true, // "certify_signer": "Simon Kreuz", // "incoterm": "DDU", // "items": [{ // "description": "T-shirt", // "quantity": 20, // "net_weight": "5", // "mass_unit": "lb", // "value_amount": "200", // "value_currency": "USD", // "tariff_number": "", // "origin_country": "US" // }] // }' // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "contents_type": "MERCHANDISE", // "non_delivery_option": "RETURN", // "certify": true, // "certify_signer": "Simon Kreuz", // "incoterm": "DDU", // "items": [ // { // "description": "T-shirt", // "quantity": 20, // "net_weight": "5", // "mass_unit": "lb", // "value_amount": "200", // "value_currency": "USD", // "tariff_number": "", // "origin_country": "US" // } // ] // } let json = CkoJsonObject() json.UpdateString("contents_type", value: "MERCHANDISE") json.UpdateString("non_delivery_option", value: "RETURN") json.UpdateBool("certify", value: true) json.UpdateString("certify_signer", value: "Simon Kreuz") json.UpdateString("incoterm", value: "DDU") json.UpdateString("items[0].description", value: "T-shirt") json.UpdateInt("items[0].quantity", value: 20) json.UpdateString("items[0].net_weight", value: "5") json.UpdateString("items[0].mass_unit", value: "lb") json.UpdateString("items[0].value_amount", value: "200") json.UpdateString("items[0].value_currency", value: "USD") json.UpdateString("items[0].tariff_number", value: "") json.UpdateString("items[0].origin_country", value: "US") http.SetRequestHeader("Authorization", value: "ShippoToken <API_TOKEN>") http.SetRequestHeader("Content-Type", value: "application/json") var resp: CkoHttpResponse? = http.PostJson3("https://api.goshippo.com/customs/declarations/", contentType: "application/json", json: json) if http.LastMethodSuccess == false { print("\(http.LastErrorText)") return } let sbResponseBody = CkoStringBuilder() resp!.GetBodySb(sbResponseBody) let jResp = CkoJsonObject() jResp.LoadSb(sbResponseBody) jResp.EmitCompact = false print("Response Body:") print("\(jResp.Emit())") var respStatusCode: Int = resp!.StatusCode.intValue print("Response Status Code = \(respStatusCode)") if respStatusCode >= 400 { print("Response Header:") print("\(resp!.Header)") print("Failed.") resp = nil return } resp = nil // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "object_created": "2019-07-04T16:00:29.043Z", // "object_updated": "2019-07-04T16:00:29.043Z", // "object_id": "4a1e6ab7b1ba49ed9bc6cb1a8798e0fd", // "object_owner": "admin@chilkatsoft.com", // "object_state": "VALID", // "address_importer": null, // "certify_signer": "Simon Kreuz", // "certify": true, // "items": [ // "4096c68693364b7ea0af72fb869ee861" // ], // "non_delivery_option": "RETURN", // "contents_type": "MERCHANDISE", // "contents_explanation": "", // "exporter_reference": "", // "importer_reference": "", // "invoice": "", // "commercial_invoice": false, // "license": "", // "certificate": "", // "notes": "", // "eel_pfc": "", // "aes_itn": "", // "disclaimer": "", // "incoterm": "DDU", // "metadata": "", // "test": true, // "duties_payor": null // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON var strVal: String? var object_created: String? = jResp.StringOf("object_created") var object_updated: String? = jResp.StringOf("object_updated") var object_id: String? = jResp.StringOf("object_id") var object_owner: String? = jResp.StringOf("object_owner") var object_state: String? = jResp.StringOf("object_state") var address_importer: String? = jResp.StringOf("address_importer") var certify_signer: String? = jResp.StringOf("certify_signer") var certify: Bool = jResp.BoolOf("certify") var non_delivery_option: String? = jResp.StringOf("non_delivery_option") var contents_type: String? = jResp.StringOf("contents_type") var contents_explanation: String? = jResp.StringOf("contents_explanation") var exporter_reference: String? = jResp.StringOf("exporter_reference") var importer_reference: String? = jResp.StringOf("importer_reference") var invoice: String? = jResp.StringOf("invoice") var commercial_invoice: Bool = jResp.BoolOf("commercial_invoice") var license: String? = jResp.StringOf("license") var certificate: String? = jResp.StringOf("certificate") var notes: String? = jResp.StringOf("notes") var eel_pfc: String? = jResp.StringOf("eel_pfc") var aes_itn: String? = jResp.StringOf("aes_itn") var disclaimer: String? = jResp.StringOf("disclaimer") var incoterm: String? = jResp.StringOf("incoterm") var metadata: String? = jResp.StringOf("metadata") var test: Bool = jResp.BoolOf("test") var duties_payor: String? = jResp.StringOf("duties_payor") var i: Int = 0 var count_i: Int = jResp.SizeOfArray("items").intValue while i < count_i { jResp.I = i strVal = jResp.StringOf("items[i]") i = i + 1 } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.