Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loHttp = createobject("CkHttp")

// 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"
//     }
//   ]
// }

loJson = createobject("CkJsonObject")
loJson.UpdateString("contents_type","MERCHANDISE")
loJson.UpdateString("non_delivery_option","RETURN")
loJson.UpdateBool("certify",.T.)
loJson.UpdateString("certify_signer","Simon Kreuz")
loJson.UpdateString("incoterm","DDU")
loJson.UpdateString("items[0].description","T-shirt")
loJson.UpdateInt("items[0].quantity",20)
loJson.UpdateString("items[0].net_weight","5")
loJson.UpdateString("items[0].mass_unit","lb")
loJson.UpdateString("items[0].value_amount","200")
loJson.UpdateString("items[0].value_currency","USD")
loJson.UpdateString("items[0].tariff_number","")
loJson.UpdateString("items[0].origin_country","US")

loHttp.SetRequestHeader("Authorization","ShippoToken <API_TOKEN>")
loHttp.SetRequestHeader("Content-Type","application/json")

loResp = createobject("CkHttpResponse")
llSuccess = loHttp.HttpJson("POST","https://api.goshippo.com/customs/declarations/",loJson,"application/json",loResp)
if (llSuccess = .F.) then
    ? loHttp.LastErrorText
    release loHttp
    release loJson
    release loResp
    return
endif

loSbResponseBody = createobject("CkStringBuilder")
loResp.GetBodySb(loSbResponseBody)
loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
    ? "Response Header:"
    ? loResp.Header
    ? "Failed."
    release loHttp
    release loJson
    release loResp
    release loSbResponseBody
    release loJResp
    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

lcObject_created = loJResp.StringOf("object_created")
lcObject_updated = loJResp.StringOf("object_updated")
lcObject_id = loJResp.StringOf("object_id")
lcObject_owner = loJResp.StringOf("object_owner")
lcObject_state = loJResp.StringOf("object_state")
lcAddress_importer = loJResp.StringOf("address_importer")
lcCertify_signer = loJResp.StringOf("certify_signer")
llCertify = loJResp.BoolOf("certify")
lcNon_delivery_option = loJResp.StringOf("non_delivery_option")
lcContents_type = loJResp.StringOf("contents_type")
lcContents_explanation = loJResp.StringOf("contents_explanation")
lcExporter_reference = loJResp.StringOf("exporter_reference")
lcImporter_reference = loJResp.StringOf("importer_reference")
lcInvoice = loJResp.StringOf("invoice")
llCommercial_invoice = loJResp.BoolOf("commercial_invoice")
lcLicense = loJResp.StringOf("license")
lcCertificate = loJResp.StringOf("certificate")
lcNotes = loJResp.StringOf("notes")
lcEel_pfc = loJResp.StringOf("eel_pfc")
lcAes_itn = loJResp.StringOf("aes_itn")
lcDisclaimer = loJResp.StringOf("disclaimer")
lcIncoterm = loJResp.StringOf("incoterm")
lcMetadata = loJResp.StringOf("metadata")
llTest = loJResp.BoolOf("test")
lcDuties_payor = loJResp.StringOf("duties_payor")
i = 0
lnCount_i = loJResp.SizeOfArray("items")
do while i < lnCount_i
    loJResp.I = i
    lcStrVal = loJResp.StringOf("items[i]")
    i = i + 1
enddo


release loHttp
release loJson
release loResp
release loSbResponseBody
release loJResp