![]() |
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
(AutoIt) 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. $oHttp = ObjCreate("Chilkat.Http") Local $bSuccess ; 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" ; } ; ] ; } $oJson = ObjCreate("Chilkat.JsonObject") $oJson.UpdateString("contents_type","MERCHANDISE") $oJson.UpdateString("non_delivery_option","RETURN") $oJson.UpdateBool("certify",True) $oJson.UpdateString("certify_signer","Simon Kreuz") $oJson.UpdateString("incoterm","DDU") $oJson.UpdateString("items[0].description","T-shirt") $oJson.UpdateInt("items[0].quantity",20) $oJson.UpdateString("items[0].net_weight","5") $oJson.UpdateString("items[0].mass_unit","lb") $oJson.UpdateString("items[0].value_amount","200") $oJson.UpdateString("items[0].value_currency","USD") $oJson.UpdateString("items[0].tariff_number","") $oJson.UpdateString("items[0].origin_country","US") $oHttp.SetRequestHeader "Authorization","ShippoToken <API_TOKEN>" $oHttp.SetRequestHeader "Content-Type","application/json" Local $oResp = $oHttp.PostJson3("https://api.goshippo.com/customs/declarations/","application/json",$oJson) If ($oHttp.LastMethodSuccess = False) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) Exit EndIf $oSbResponseBody = ObjCreate("Chilkat.StringBuilder") $oResp.GetBodySb($oSbResponseBody) $oJResp = ObjCreate("Chilkat.JsonObject") $oJResp.LoadSb($oSbResponseBody) $oJResp.EmitCompact = False ConsoleWrite("Response Body:" & @CRLF) ConsoleWrite($oJResp.Emit() & @CRLF) Local $iRespStatusCode = $oResp.StatusCode ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF) If ($iRespStatusCode >= 400) Then ConsoleWrite("Response Header:" & @CRLF) ConsoleWrite($oResp.Header & @CRLF) ConsoleWrite("Failed." & @CRLF) Exit EndIf ; 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 Local $sTemplate Local $sLength Local $sWidth Local $sHeight Local $sDistance_unit Local $sWeight Local $sMass_unit Local $sValue_amount Local $sValue_currency Local $bTest Local $iJ Local $iCount_j Local $intVal Local $sObject_created = $oJResp.StringOf("object_created") Local $sObject_updated = $oJResp.StringOf("object_updated") Local $sObject_id = $oJResp.StringOf("object_id") Local $sObject_owner = $oJResp.StringOf("object_owner") Local $status = $oJResp.StringOf("status") Local $sAddress_fromObject_id = $oJResp.StringOf("address_from.object_id") Local $bAddress_fromIs_complete = $oJResp.BoolOf("address_from.is_complete") Local $sAddress_fromCompany = $oJResp.StringOf("address_from.company") Local $sAddress_fromStreet_no = $oJResp.StringOf("address_from.street_no") Local $sAddress_fromName = $oJResp.StringOf("address_from.name") Local $sAddress_fromStreet1 = $oJResp.StringOf("address_from.street1") Local $sAddress_fromStreet2 = $oJResp.StringOf("address_from.street2") Local $sAddress_fromCity = $oJResp.StringOf("address_from.city") Local $sAddress_fromState = $oJResp.StringOf("address_from.state") Local $sAddress_fromZip = $oJResp.StringOf("address_from.zip") Local $sAddress_fromCountry = $oJResp.StringOf("address_from.country") Local $sAddress_fromPhone = $oJResp.StringOf("address_from.phone") Local $sAddress_fromEmail = $oJResp.StringOf("address_from.email") Local $sAddress_fromIs_residential = $oJResp.StringOf("address_from.is_residential") Local $sAddress_toObject_id = $oJResp.StringOf("address_to.object_id") Local $bAddress_toIs_complete = $oJResp.BoolOf("address_to.is_complete") Local $sAddress_toName = $oJResp.StringOf("address_to.name") Local $sAddress_toStreet1 = $oJResp.StringOf("address_to.street1") Local $sAddress_toCity = $oJResp.StringOf("address_to.city") Local $sAddress_toState = $oJResp.StringOf("address_to.state") Local $sAddress_toZip = $oJResp.StringOf("address_to.zip") Local $sAddress_toCountry = $oJResp.StringOf("address_to.country") Local $sAddress_toPhone = $oJResp.StringOf("address_to.phone") Local $sAddress_toEmail = $oJResp.StringOf("address_to.email") Local $bAddress_toIs_residential = $oJResp.BoolOf("address_to.is_residential") Local $sAddress_return = $oJResp.StringOf("address_return") Local $shipment_date = $oJResp.StringOf("shipment_date") Local $sExtraInsuranceCurrency = $oJResp.StringOf("extra.insurance.currency") Local $sExtraInsuranceAmount = $oJResp.StringOf("extra.insurance.amount") Local $sExtraReference_1 = $oJResp.StringOf("extra.reference_1") Local $sExtraReference_2 = $oJResp.StringOf("extra.reference_2") Local $sCustoms_declaration = $oJResp.StringOf("customs_declaration") Local $sMetadata = $oJResp.StringOf("metadata") Local $i = 0 Local $iCount_i = $oJResp.SizeOfArray("parcels") While $i < $iCount_i $oJResp.I = $i $sObject_id = $oJResp.StringOf("parcels[i].object_id") $sObject_created = $oJResp.StringOf("parcels[i].object_created") $sObject_updated = $oJResp.StringOf("parcels[i].object_updated") $sObject_owner = $oJResp.StringOf("parcels[i].object_owner") $sTemplate = $oJResp.StringOf("parcels[i].template") $sLength = $oJResp.StringOf("parcels[i].length") $sWidth = $oJResp.StringOf("parcels[i].width") $sHeight = $oJResp.StringOf("parcels[i].height") $sDistance_unit = $oJResp.StringOf("parcels[i].distance_unit") $sWeight = $oJResp.StringOf("parcels[i].weight") $sMass_unit = $oJResp.StringOf("parcels[i].mass_unit") $sValue_amount = $oJResp.StringOf("parcels[i].value_amount") $sValue_currency = $oJResp.StringOf("parcels[i].value_currency") $sMetadata = $oJResp.StringOf("parcels[i].metadata") $bTest = $oJResp.BoolOf("parcels[i].test") $iJ = 0 $iCount_j = $oJResp.SizeOfArray("parcels[i].line_items") While $iJ < $iCount_j $oJResp.J = $iJ $iJ = $iJ + 1 Wend $i = $i + 1 Wend $i = 0 $iCount_i = $oJResp.SizeOfArray("rates") While $i < $iCount_i $oJResp.I = $i $intVal = $oJResp.IntOf("rates[i]") $iJ = 0 $iCount_j = $oJResp.SizeOfArray("rates[i].attributes") While $iJ < $iCount_j $oJResp.J = $iJ $iJ = $iJ + 1 Wend $iJ = 0 $iCount_j = $oJResp.SizeOfArray("rates[i].messages") While $iJ < $iCount_j $oJResp.J = $iJ $iJ = $iJ + 1 Wend $i = $i + 1 Wend $i = 0 $iCount_i = $oJResp.SizeOfArray("carrier_accounts") While $i < $iCount_i $oJResp.I = $i $i = $i + 1 Wend $i = 0 $iCount_i = $oJResp.SizeOfArray("messages") While $i < $iCount_i $oJResp.I = $i $i = $i + 1 Wend |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.