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 3,4,5...) 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.update("contents_type", value: "MERCHANDISE") json.update("non_delivery_option", value: "RETURN") json.updateBool("certify", value: true) json.update("certify_signer", value: "Simon Kreuz") json.update("incoterm", value: "DDU") json.update("items[0].description", value: "T-shirt") json.updateInt("items[0].quantity", value: 20) json.update("items[0].net_weight", value: "5") json.update("items[0].mass_unit", value: "lb") json.update("items[0].value_amount", value: "200") json.update("items[0].value_currency", value: "USD") json.update("items[0].tariff_number", value: "") json.update("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.string(of: "object_created") var object_updated: String? = jResp.string(of: "object_updated") var object_id: String? = jResp.string(of: "object_id") var object_owner: String? = jResp.string(of: "object_owner") var object_state: String? = jResp.string(of: "object_state") var address_importer: String? = jResp.string(of: "address_importer") var certify_signer: String? = jResp.string(of: "certify_signer") var certify: Bool = jResp.bool(of: "certify") var non_delivery_option: String? = jResp.string(of: "non_delivery_option") var contents_type: String? = jResp.string(of: "contents_type") var contents_explanation: String? = jResp.string(of: "contents_explanation") var exporter_reference: String? = jResp.string(of: "exporter_reference") var importer_reference: String? = jResp.string(of: "importer_reference") var invoice: String? = jResp.string(of: "invoice") var commercial_invoice: Bool = jResp.bool(of: "commercial_invoice") var license: String? = jResp.string(of: "license") var certificate: String? = jResp.string(of: "certificate") var notes: String? = jResp.string(of: "notes") var eel_pfc: String? = jResp.string(of: "eel_pfc") var aes_itn: String? = jResp.string(of: "aes_itn") var disclaimer: String? = jResp.string(of: "disclaimer") var incoterm: String? = jResp.string(of: "incoterm") var metadata: String? = jResp.string(of: "metadata") var test: Bool = jResp.bool(of: "test") var duties_payor: String? = jResp.string(of: "duties_payor") var i: Int = 0 var count_i: Int = jResp.size(ofArray: "items").intValue while i < count_i { jResp.i = i strVal = jResp.string(of: "items[i]") i = i + 1 } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.