Xbase++
Xbase++
Shippo Create Customs Declaration
See more Shippo Examples
Demonstrates how to create a customs declaration and send a POST request with the necessary information to the Customs Declarations endpoint.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cStrVal
LOCAL cObject_created
LOCAL cObject_updated
LOCAL cObject_id
LOCAL cObject_owner
LOCAL cObject_state
LOCAL cAddress_importer
LOCAL cCertify_signer
LOCAL nCertify
LOCAL cNon_delivery_option
LOCAL cContents_type
LOCAL cContents_explanation
LOCAL cExporter_reference
LOCAL cImporter_reference
LOCAL cInvoice
LOCAL nCommercial_invoice
LOCAL cLicense
LOCAL cCertificate
LOCAL cNotes
LOCAL cEel_pfc
LOCAL cAes_itn
LOCAL cDisclaimer
LOCAL cIncoterm
LOCAL cMetadata
LOCAL nTest
LOCAL cDuties_payor
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// 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 := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("contents_type", "MERCHANDISE")
oJson:UpdateString("non_delivery_option", "RETURN")
oJson:UpdateBool("certify", 1)
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")
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://api.goshippo.com/customs/declarations/", oJson, "application/json", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJson:destroy()
oResp:destroy()
RETURN
ENDIF
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oResp:Header
? "Failed."
oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
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
cObject_created := oJResp:StringOf("object_created")
cObject_updated := oJResp:StringOf("object_updated")
cObject_id := oJResp:StringOf("object_id")
cObject_owner := oJResp:StringOf("object_owner")
cObject_state := oJResp:StringOf("object_state")
cAddress_importer := oJResp:StringOf("address_importer")
cCertify_signer := oJResp:StringOf("certify_signer")
nCertify := oJResp:BoolOf("certify")
cNon_delivery_option := oJResp:StringOf("non_delivery_option")
cContents_type := oJResp:StringOf("contents_type")
cContents_explanation := oJResp:StringOf("contents_explanation")
cExporter_reference := oJResp:StringOf("exporter_reference")
cImporter_reference := oJResp:StringOf("importer_reference")
cInvoice := oJResp:StringOf("invoice")
nCommercial_invoice := oJResp:BoolOf("commercial_invoice")
cLicense := oJResp:StringOf("license")
cCertificate := oJResp:StringOf("certificate")
cNotes := oJResp:StringOf("notes")
cEel_pfc := oJResp:StringOf("eel_pfc")
cAes_itn := oJResp:StringOf("aes_itn")
cDisclaimer := oJResp:StringOf("disclaimer")
cIncoterm := oJResp:StringOf("incoterm")
cMetadata := oJResp:StringOf("metadata")
nTest := oJResp:BoolOf("test")
cDuties_payor := oJResp:StringOf("duties_payor")
i := 0
nCount_i := oJResp:SizeOfArray("items")
DO WHILE i < nCount_i
oJResp:I := i
cStrVal := oJResp:StringOf("items[i]")
i := i + 1
ENDDO
oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()