Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(C# UWP/WinRT) 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. Chilkat.Http http = new Chilkat.Http(); bool success; // 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" // } // ] // } Chilkat.JsonObject json = new Chilkat.JsonObject(); json.UpdateString("contents_type","MERCHANDISE"); json.UpdateString("non_delivery_option","RETURN"); json.UpdateBool("certify",true); json.UpdateString("certify_signer","Simon Kreuz"); json.UpdateString("incoterm","DDU"); json.UpdateString("items[0].description","T-shirt"); json.UpdateInt("items[0].quantity",20); json.UpdateString("items[0].net_weight","5"); json.UpdateString("items[0].mass_unit","lb"); json.UpdateString("items[0].value_amount","200"); json.UpdateString("items[0].value_currency","USD"); json.UpdateString("items[0].tariff_number",""); json.UpdateString("items[0].origin_country","US"); http.SetRequestHeader("Authorization","ShippoToken <API_TOKEN>"); http.SetRequestHeader("Content-Type","application/json"); Chilkat.HttpResponse resp = await http.PostJson3Async("https://api.goshippo.com/customs/declarations/","application/json",json); if (http.LastMethodSuccess == false) { Debug.WriteLine(http.LastErrorText); return; } Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder(); resp.GetBodySb(sbResponseBody); Chilkat.JsonObject jResp = new Chilkat.JsonObject(); jResp.LoadSb(sbResponseBody); jResp.EmitCompact = false; Debug.WriteLine("Response Body:"); Debug.WriteLine(jResp.Emit()); int respStatusCode = resp.StatusCode; Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode)); if (respStatusCode >= 400) { Debug.WriteLine("Response Header:"); Debug.WriteLine(resp.Header); Debug.WriteLine("Failed."); return; } // 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 string strVal; string object_created = jResp.StringOf("object_created"); string object_updated = jResp.StringOf("object_updated"); string object_id = jResp.StringOf("object_id"); string object_owner = jResp.StringOf("object_owner"); string object_state = jResp.StringOf("object_state"); string address_importer = jResp.StringOf("address_importer"); string certify_signer = jResp.StringOf("certify_signer"); bool certify = jResp.BoolOf("certify"); string non_delivery_option = jResp.StringOf("non_delivery_option"); string contents_type = jResp.StringOf("contents_type"); string contents_explanation = jResp.StringOf("contents_explanation"); string exporter_reference = jResp.StringOf("exporter_reference"); string importer_reference = jResp.StringOf("importer_reference"); string invoice = jResp.StringOf("invoice"); bool commercial_invoice = jResp.BoolOf("commercial_invoice"); string license = jResp.StringOf("license"); string certificate = jResp.StringOf("certificate"); string notes = jResp.StringOf("notes"); string eel_pfc = jResp.StringOf("eel_pfc"); string aes_itn = jResp.StringOf("aes_itn"); string disclaimer = jResp.StringOf("disclaimer"); string incoterm = jResp.StringOf("incoterm"); string metadata = jResp.StringOf("metadata"); bool test = jResp.BoolOf("test"); string duties_payor = jResp.StringOf("duties_payor"); int i = 0; int count_i = jResp.SizeOfArray("items"); while (i < count_i) { jResp.I = i; strVal = jResp.StringOf("items[i]"); i = i + 1; } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.