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
(DataFlex) 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/
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Boolean iSuccess Variant vJson Handle hoJson Variant vResp Handle hoResp Variant vSbResponseBody Handle hoSbResponseBody Handle hoJResp Integer iRespStatusCode String sStrVal String sObject_created String sObject_updated String sObject_id String sObject_owner String sObject_state String sAddress_importer String sCertify_signer Boolean iCertify String sNon_delivery_option String sContents_type String sContents_explanation String sExporter_reference String sImporter_reference String sInvoice Boolean iCommercial_invoice String sLicense String sCertificate String sNotes String sEel_pfc String sAes_itn String sDisclaimer String sIncoterm String sMetadata Boolean iTest String sDuties_payor Integer i Integer iCount_i String sTemp1 Boolean bTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End // 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" // } // ] // } Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComUpdateString Of hoJson "contents_type" "MERCHANDISE" To iSuccess Get ComUpdateString Of hoJson "non_delivery_option" "RETURN" To iSuccess Get ComUpdateBool Of hoJson "certify" True To iSuccess Get ComUpdateString Of hoJson "certify_signer" "Simon Kreuz" To iSuccess Get ComUpdateString Of hoJson "incoterm" "DDU" To iSuccess Get ComUpdateString Of hoJson "items[0].description" "T-shirt" To iSuccess Get ComUpdateInt Of hoJson "items[0].quantity" 20 To iSuccess Get ComUpdateString Of hoJson "items[0].net_weight" "5" To iSuccess Get ComUpdateString Of hoJson "items[0].mass_unit" "lb" To iSuccess Get ComUpdateString Of hoJson "items[0].value_amount" "200" To iSuccess Get ComUpdateString Of hoJson "items[0].value_currency" "USD" To iSuccess Get ComUpdateString Of hoJson "items[0].tariff_number" "" To iSuccess Get ComUpdateString Of hoJson "items[0].origin_country" "US" To iSuccess Send ComSetRequestHeader To hoHttp "Authorization" "ShippoToken <API_TOKEN>" Send ComSetRequestHeader To hoHttp "Content-Type" "application/json" Get pvComObject of hoJson to vJson Get ComPostJson3 Of hoHttp "https://api.goshippo.com/customs/declarations/" "application/json" vJson To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody If (Not(IsComObjectCreated(hoSbResponseBody))) Begin Send CreateComObject of hoSbResponseBody End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess Get Create (RefClass(cComChilkatJsonObject)) To hoJResp If (Not(IsComObjectCreated(hoJResp))) Begin Send CreateComObject of hoJResp End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess Set ComEmitCompact Of hoJResp To False Showln "Response Body:" Get ComEmit Of hoJResp To sTemp1 Showln sTemp1 Get ComStatusCode Of hoResp To iRespStatusCode Showln "Response Status Code = " iRespStatusCode If (iRespStatusCode >= 400) Begin Showln "Response Header:" Get ComHeader Of hoResp To sTemp1 Showln sTemp1 Showln "Failed." Send Destroy of hoResp Procedure_Return End Send Destroy of hoResp // 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 Get ComStringOf Of hoJResp "object_created" To sObject_created Get ComStringOf Of hoJResp "object_updated" To sObject_updated Get ComStringOf Of hoJResp "object_id" To sObject_id Get ComStringOf Of hoJResp "object_owner" To sObject_owner Get ComStringOf Of hoJResp "object_state" To sObject_state Get ComStringOf Of hoJResp "address_importer" To sAddress_importer Get ComStringOf Of hoJResp "certify_signer" To sCertify_signer Get ComBoolOf Of hoJResp "certify" To iCertify Get ComStringOf Of hoJResp "non_delivery_option" To sNon_delivery_option Get ComStringOf Of hoJResp "contents_type" To sContents_type Get ComStringOf Of hoJResp "contents_explanation" To sContents_explanation Get ComStringOf Of hoJResp "exporter_reference" To sExporter_reference Get ComStringOf Of hoJResp "importer_reference" To sImporter_reference Get ComStringOf Of hoJResp "invoice" To sInvoice Get ComBoolOf Of hoJResp "commercial_invoice" To iCommercial_invoice Get ComStringOf Of hoJResp "license" To sLicense Get ComStringOf Of hoJResp "certificate" To sCertificate Get ComStringOf Of hoJResp "notes" To sNotes Get ComStringOf Of hoJResp "eel_pfc" To sEel_pfc Get ComStringOf Of hoJResp "aes_itn" To sAes_itn Get ComStringOf Of hoJResp "disclaimer" To sDisclaimer Get ComStringOf Of hoJResp "incoterm" To sIncoterm Get ComStringOf Of hoJResp "metadata" To sMetadata Get ComBoolOf Of hoJResp "test" To iTest Get ComStringOf Of hoJResp "duties_payor" To sDuties_payor Move 0 To i Get ComSizeOfArray Of hoJResp "items" To iCount_i While (i < iCount_i) Set ComI Of hoJResp To i Get ComStringOf Of hoJResp "items[i]" To sStrVal Move (i + 1) To i Loop End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.