Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_StrVal
string ls_Object_created
string ls_Object_updated
string ls_Object_id
string ls_Object_owner
string ls_Object_state
string ls_Address_importer
string ls_Certify_signer
integer li_Certify
string ls_Non_delivery_option
string ls_Contents_type
string ls_Contents_explanation
string ls_Exporter_reference
string ls_Importer_reference
string ls_Invoice
integer li_Commercial_invoice
string ls_License
string ls_Certificate
string ls_Notes
string ls_Eel_pfc
string ls_Aes_itn
string ls_Disclaimer
string ls_Incoterm
string ls_Metadata
integer li_Test
string ls_Duties_payor
integer i
integer li_Count_i

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

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

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

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpJson("POST","https://api.goshippo.com/customs/declarations/",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

// 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

ls_Object_created = loo_JResp.StringOf("object_created")
ls_Object_updated = loo_JResp.StringOf("object_updated")
ls_Object_id = loo_JResp.StringOf("object_id")
ls_Object_owner = loo_JResp.StringOf("object_owner")
ls_Object_state = loo_JResp.StringOf("object_state")
ls_Address_importer = loo_JResp.StringOf("address_importer")
ls_Certify_signer = loo_JResp.StringOf("certify_signer")
li_Certify = loo_JResp.BoolOf("certify")
ls_Non_delivery_option = loo_JResp.StringOf("non_delivery_option")
ls_Contents_type = loo_JResp.StringOf("contents_type")
ls_Contents_explanation = loo_JResp.StringOf("contents_explanation")
ls_Exporter_reference = loo_JResp.StringOf("exporter_reference")
ls_Importer_reference = loo_JResp.StringOf("importer_reference")
ls_Invoice = loo_JResp.StringOf("invoice")
li_Commercial_invoice = loo_JResp.BoolOf("commercial_invoice")
ls_License = loo_JResp.StringOf("license")
ls_Certificate = loo_JResp.StringOf("certificate")
ls_Notes = loo_JResp.StringOf("notes")
ls_Eel_pfc = loo_JResp.StringOf("eel_pfc")
ls_Aes_itn = loo_JResp.StringOf("aes_itn")
ls_Disclaimer = loo_JResp.StringOf("disclaimer")
ls_Incoterm = loo_JResp.StringOf("incoterm")
ls_Metadata = loo_JResp.StringOf("metadata")
li_Test = loo_JResp.BoolOf("test")
ls_Duties_payor = loo_JResp.StringOf("duties_payor")
i = 0
li_Count_i = loo_JResp.SizeOfArray("items")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("items[i]")
    i = i + 1
loop


destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp