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 an OrderDemonstrates how to create an order with all the information about your order by sending a POST request to the orders endpoint. For more information, see https://goshippo.com/docs/orders/
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/orders/ \ // -H "Authorization: ShippoToken <API_Token>" \ // -H "Content-Type: application/json" \ // -d '{ // "to_address": { // "city": "San Francisco", // "company": "Shippo", // "country": "US", // "email": "shippotle@goshippo.com", // "name": "Mr Hippo", // "phone": "15553419393", // "state": "CA", // "street1": "215 Clayton St.", // "zip": "94117" // }, // "line_items": [ // { // "quantity": 1, // "sku": "HM-123", // "title": "Hippo Magazines", // "total_price": "12.10", // "currency": "USD", // "weight": "0.40", // "weight_unit": "lb" // } // ], // "placed_at": "2016-09-23T01:28:12Z", // "order_number": "#1068", // "order_status": "PAID", // "shipping_cost": "12.83", // "shipping_cost_currency": "USD", // "shipping_method": "USPS First Class Package", // "subtotal_price": "12.10", // "total_price": "24.93", // "total_tax": "0.00", // "currency": "USD", // "weight": "0.40", // "weight_unit": "lb" // }' // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "to_address": { // "city": "San Francisco", // "company": "Shippo", // "country": "US", // "email": "shippotle@goshippo.com", // "name": "Mr Hippo", // "phone": "15553419393", // "state": "CA", // "street1": "215 Clayton St.", // "zip": "94117" // }, // "line_items": [ // { // "quantity": 1, // "sku": "HM-123", // "title": "Hippo Magazines", // "total_price": "12.10", // "currency": "USD", // "weight": "0.40", // "weight_unit": "lb" // } // ], // "placed_at": "2016-09-23T01:28:12Z", // "order_number": "#1068", // "order_status": "PAID", // "shipping_cost": "12.83", // "shipping_cost_currency": "USD", // "shipping_method": "USPS First Class Package", // "subtotal_price": "12.10", // "total_price": "24.93", // "total_tax": "0.00", // "currency": "USD", // "weight": "0.40", // "weight_unit": "lb" // } let json = CkoJsonObject()! json.update("to_address.city", value: "San Francisco") json.update("to_address.company", value: "Shippo") json.update("to_address.country", value: "US") json.update("to_address.email", value: "shippotle@goshippo.com") json.update("to_address.name", value: "Mr Hippo") json.update("to_address.phone", value: "15553419393") json.update("to_address.state", value: "CA") json.update("to_address.street1", value: "215 Clayton St.") json.update("to_address.zip", value: "94117") json.updateInt("line_items[0].quantity", value: 1) json.update("line_items[0].sku", value: "HM-123") json.update("line_items[0].title", value: "Hippo Magazines") json.update("line_items[0].total_price", value: "12.10") json.update("line_items[0].currency", value: "USD") json.update("line_items[0].weight", value: "0.40") json.update("line_items[0].weight_unit", value: "lb") json.update("placed_at", value: "2016-09-23T01:28:12Z") json.update("order_number", value: "#1068") json.update("order_status", value: "PAID") json.update("shipping_cost", value: "12.83") json.update("shipping_cost_currency", value: "USD") json.update("shipping_method", value: "USPS First Class Package") json.update("subtotal_price", value: "12.10") json.update("total_price", value: "24.93") json.update("total_tax", value: "0.00") json.update("currency", value: "USD") json.update("weight", value: "0.40") json.update("weight_unit", value: "lb") http.setRequestHeader("Authorization", value: "ShippoToken <API_Token>") http.setRequestHeader("Content-Type", value: "application/json") var resp: CkoHttpResponse? = http.postJson3("https://api.goshippo.com/orders/", 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) // {} // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.