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
(AutoIt) 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/
; 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": "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 Local $strVal 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 $sObject_state = $oJResp.StringOf("object_state") Local $sAddress_importer = $oJResp.StringOf("address_importer") Local $sCertify_signer = $oJResp.StringOf("certify_signer") Local $bCertify = $oJResp.BoolOf("certify") Local $sNon_delivery_option = $oJResp.StringOf("non_delivery_option") Local $sContents_type = $oJResp.StringOf("contents_type") Local $sContents_explanation = $oJResp.StringOf("contents_explanation") Local $sExporter_reference = $oJResp.StringOf("exporter_reference") Local $sImporter_reference = $oJResp.StringOf("importer_reference") Local $sInvoice = $oJResp.StringOf("invoice") Local $bCommercial_invoice = $oJResp.BoolOf("commercial_invoice") Local $sLicense = $oJResp.StringOf("license") Local $sCertificate = $oJResp.StringOf("certificate") Local $sNotes = $oJResp.StringOf("notes") Local $sEel_pfc = $oJResp.StringOf("eel_pfc") Local $sAes_itn = $oJResp.StringOf("aes_itn") Local $sDisclaimer = $oJResp.StringOf("disclaimer") Local $sIncoterm = $oJResp.StringOf("incoterm") Local $sMetadata = $oJResp.StringOf("metadata") Local $bTest = $oJResp.BoolOf("test") Local $sDuties_payor = $oJResp.StringOf("duties_payor") Local $i = 0 Local $iCount_i = $oJResp.SizeOfArray("items") While $i < $iCount_i $oJResp.I = $i $strVal = $oJResp.StringOf("items[i]") $i = $i + 1 Wend |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.