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
(Xojo Plugin) Shippo Create the Shipment, Get Rates, and Purchase LabelDemonstrates how retrieve rates and create labels for international shipments. For more information, see https://goshippo.com/docs/international/
// This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Dim http As New Chilkat.Http Dim success As Boolean // 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" // } // ] // } Dim json As New Chilkat.JsonObject success = json.UpdateString("contents_type","MERCHANDISE") success = json.UpdateString("non_delivery_option","RETURN") success = json.UpdateBool("certify",True) success = json.UpdateString("certify_signer","Simon Kreuz") success = json.UpdateString("incoterm","DDU") success = json.UpdateString("items[0].description","T-shirt") success = json.UpdateInt("items[0].quantity",20) success = json.UpdateString("items[0].net_weight","5") success = json.UpdateString("items[0].mass_unit","lb") success = json.UpdateString("items[0].value_amount","200") success = json.UpdateString("items[0].value_currency","USD") success = json.UpdateString("items[0].tariff_number","") success = json.UpdateString("items[0].origin_country","US") http.SetRequestHeader "Authorization","ShippoToken <API_TOKEN>" http.SetRequestHeader "Content-Type","application/json" Dim resp As Chilkat.HttpResponse resp = http.PostJson3("https://api.goshippo.com/customs/declarations/","application/json",json) If (http.LastMethodSuccess = False) Then System.DebugLog(http.LastErrorText) Return End If Dim sbResponseBody As New Chilkat.StringBuilder success = resp.GetBodySb(sbResponseBody) Dim jResp As New Chilkat.JsonObject success = jResp.LoadSb(sbResponseBody) jResp.EmitCompact = False System.DebugLog("Response Body:") System.DebugLog(jResp.Emit()) Dim respStatusCode As Int32 respStatusCode = resp.StatusCode System.DebugLog("Response Status Code = " + Str(respStatusCode)) If (respStatusCode >= 400) Then System.DebugLog("Response Header:") System.DebugLog(resp.Header) System.DebugLog("Failed.") Return End If // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "object_created": "2014-07-17T00:04:06.163Z", // "object_updated": "2014-07-17T00:04:06.163Z", // "object_id": "89436997a794439ab47999701e60392e", // "object_owner": "shippotle@goshippo.com", // "status": "SUCCESS", // "address_from": { // "object_id": "0943ae4e373e4120a99c337e496dcce8", // "validation_results": {}, // "is_complete": true, // "company": "", // "street_no": "", // "name": "Mr. Hippo", // "street1": "215 Clayton St.", // "street2": "", // "city": "San Francisco", // "state": "CA", // "zip": "94117", // "country": "US", // "phone": "+15553419393", // "email": "support@goshippo.com", // "is_residential": null // }, // "address_to": { // "object_id": "4c7185d353764d0985a6a7825aed8ffb", // "validation_results": {}, // "is_complete": true, // "name": "Mrs. Hippo", // "street1": "200 University Ave W", // "city": "Waterloo", // "state": "ON", // "zip": "N2L 3G1", // "country": "CA", // "phone": "+1 555 341 9393", // "email": "support@goshippo.com", // "is_residential": false // }, // "address_return": null, // "parcels": [ // { // "object_id": "ec952343dd4843c39b42aca620471fd5", // "object_created": "2013-12-01T06:24:21.121Z", // "object_updated": "2013-12-01T06:24:21.121Z", // "object_owner": "shippotle@goshippo.com", // "template": null, // "length": "5", // "width": "5", // "height": "5", // "distance_unit": "in", // "weight": "2", // "mass_unit": "lb", // "value_amount": null, // "value_currency": null, // "metadata": "", // "line_items": [ // ], // "test": true // } // ], // "shipment_date": "2013-12-03T12:00:00Z", // "extra": { // "insurance": { // "currency": "", // "amount": "" // }, // "reference_1": "", // "reference_2": "" // }, // "customs_declaration": "b741b99f95e841639b54272834bc478c", // "rates": [ // { // "object_created": "2014-07-17T00:04:06.263Z", // "object_id": "545ab0a1a6ea4c9f9adb2512a57d6d8b", // "object_owner": "shippotle@goshippo.com", // "shipment": "89436997a794439ab47999701e60392e", // "attributes": [ // ], // "amount": "5.50", // "currency": "USD", // "amount_local": "5.50", // "currency_local": "USD", // "provider": "USPS", // "provider_image_75": "https://cdn2.goshippo.com/providers/75/USPS.png", // "provider_image_200": "https://cdn2.goshippo.com/providers/200/USPS.png", // "servicelevel": { // "name": "Priority Mail", // "token": "usps_priority", // "terms": "" // }, // "days": 2, // "arrives_by": null, // "duration_terms": "Delivery in 1 to 3 business days.", // "messages": [ // ], // "carrier_account": "078870331023437cb917f5187429b093", // "test": false, // "zone": 1 // }, // ... // ], // "carrier_accounts": [ // ], // "messages": [ // ], // "metadata": "Customer ID 123456" // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON Dim template As String Dim length As String Dim width As String Dim height As String Dim distance_unit As String Dim weight As String Dim mass_unit As String Dim value_amount As String Dim value_currency As String Dim test As Boolean Dim j As Int32 Dim count_j As Int32 Dim intVal As Int32 Dim object_created As String object_created = jResp.StringOf("object_created") Dim object_updated As String object_updated = jResp.StringOf("object_updated") Dim object_id As String object_id = jResp.StringOf("object_id") Dim object_owner As String object_owner = jResp.StringOf("object_owner") Dim status As String status = jResp.StringOf("status") Dim address_fromObject_id As String address_fromObject_id = jResp.StringOf("address_from.object_id") Dim address_fromIs_complete As Boolean address_fromIs_complete = jResp.BoolOf("address_from.is_complete") Dim address_fromCompany As String address_fromCompany = jResp.StringOf("address_from.company") Dim address_fromStreet_no As String address_fromStreet_no = jResp.StringOf("address_from.street_no") Dim address_fromName As String address_fromName = jResp.StringOf("address_from.name") Dim address_fromStreet1 As String address_fromStreet1 = jResp.StringOf("address_from.street1") Dim address_fromStreet2 As String address_fromStreet2 = jResp.StringOf("address_from.street2") Dim address_fromCity As String address_fromCity = jResp.StringOf("address_from.city") Dim address_fromState As String address_fromState = jResp.StringOf("address_from.state") Dim address_fromZip As String address_fromZip = jResp.StringOf("address_from.zip") Dim address_fromCountry As String address_fromCountry = jResp.StringOf("address_from.country") Dim address_fromPhone As String address_fromPhone = jResp.StringOf("address_from.phone") Dim address_fromEmail As String address_fromEmail = jResp.StringOf("address_from.email") Dim address_fromIs_residential As String address_fromIs_residential = jResp.StringOf("address_from.is_residential") Dim address_toObject_id As String address_toObject_id = jResp.StringOf("address_to.object_id") Dim address_toIs_complete As Boolean address_toIs_complete = jResp.BoolOf("address_to.is_complete") Dim address_toName As String address_toName = jResp.StringOf("address_to.name") Dim address_toStreet1 As String address_toStreet1 = jResp.StringOf("address_to.street1") Dim address_toCity As String address_toCity = jResp.StringOf("address_to.city") Dim address_toState As String address_toState = jResp.StringOf("address_to.state") Dim address_toZip As String address_toZip = jResp.StringOf("address_to.zip") Dim address_toCountry As String address_toCountry = jResp.StringOf("address_to.country") Dim address_toPhone As String address_toPhone = jResp.StringOf("address_to.phone") Dim address_toEmail As String address_toEmail = jResp.StringOf("address_to.email") Dim address_toIs_residential As Boolean address_toIs_residential = jResp.BoolOf("address_to.is_residential") Dim address_return As String address_return = jResp.StringOf("address_return") Dim shipment_date As String shipment_date = jResp.StringOf("shipment_date") Dim extraInsuranceCurrency As String extraInsuranceCurrency = jResp.StringOf("extra.insurance.currency") Dim extraInsuranceAmount As String extraInsuranceAmount = jResp.StringOf("extra.insurance.amount") Dim extraReference_1 As String extraReference_1 = jResp.StringOf("extra.reference_1") Dim extraReference_2 As String extraReference_2 = jResp.StringOf("extra.reference_2") Dim customs_declaration As String customs_declaration = jResp.StringOf("customs_declaration") Dim metadata As String metadata = jResp.StringOf("metadata") Dim i As Int32 i = 0 Dim count_i As Int32 count_i = jResp.SizeOfArray("parcels") While i < count_i jResp.I = i object_id = jResp.StringOf("parcels[i].object_id") object_created = jResp.StringOf("parcels[i].object_created") object_updated = jResp.StringOf("parcels[i].object_updated") object_owner = jResp.StringOf("parcels[i].object_owner") template = jResp.StringOf("parcels[i].template") length = jResp.StringOf("parcels[i].length") width = jResp.StringOf("parcels[i].width") height = jResp.StringOf("parcels[i].height") distance_unit = jResp.StringOf("parcels[i].distance_unit") weight = jResp.StringOf("parcels[i].weight") mass_unit = jResp.StringOf("parcels[i].mass_unit") value_amount = jResp.StringOf("parcels[i].value_amount") value_currency = jResp.StringOf("parcels[i].value_currency") metadata = jResp.StringOf("parcels[i].metadata") test = jResp.BoolOf("parcels[i].test") j = 0 count_j = jResp.SizeOfArray("parcels[i].line_items") While j < count_j jResp.J = j j = j + 1 Wend i = i + 1 Wend i = 0 count_i = jResp.SizeOfArray("rates") While i < count_i jResp.I = i intVal = jResp.IntOf("rates[i]") j = 0 count_j = jResp.SizeOfArray("rates[i].attributes") While j < count_j jResp.J = j j = j + 1 Wend j = 0 count_j = jResp.SizeOfArray("rates[i].messages") While j < count_j jResp.J = j j = j + 1 Wend i = i + 1 Wend i = 0 count_i = jResp.SizeOfArray("carrier_accounts") While i < count_i jResp.I = i i = i + 1 Wend i = 0 count_i = jResp.SizeOfArray("messages") While i < count_i jResp.I = i i = i + 1 Wend |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.