Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, HttpResponse, JsonObject;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
strVal: PWideChar;
object_created: PWideChar;
object_updated: PWideChar;
object_id: PWideChar;
object_owner: PWideChar;
object_state: PWideChar;
address_importer: PWideChar;
certify_signer: PWideChar;
certify: Boolean;
non_delivery_option: PWideChar;
contents_type: PWideChar;
contents_explanation: PWideChar;
exporter_reference: PWideChar;
importer_reference: PWideChar;
invoice: PWideChar;
commercial_invoice: Boolean;
license: PWideChar;
certificate: PWideChar;
notes: PWideChar;
eel_pfc: PWideChar;
aes_itn: PWideChar;
disclaimer: PWideChar;
incoterm: PWideChar;
metadata: PWideChar;
test: Boolean;
duties_payor: PWideChar;
i: Integer;
count_i: Integer;

begin
success := False;

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

http := CkHttp_Create();

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

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'contents_type','MERCHANDISE');
CkJsonObject_UpdateString(json,'non_delivery_option','RETURN');
CkJsonObject_UpdateBool(json,'certify',True);
CkJsonObject_UpdateString(json,'certify_signer','Simon Kreuz');
CkJsonObject_UpdateString(json,'incoterm','DDU');
CkJsonObject_UpdateString(json,'items[0].description','T-shirt');
CkJsonObject_UpdateInt(json,'items[0].quantity',20);
CkJsonObject_UpdateString(json,'items[0].net_weight','5');
CkJsonObject_UpdateString(json,'items[0].mass_unit','lb');
CkJsonObject_UpdateString(json,'items[0].value_amount','200');
CkJsonObject_UpdateString(json,'items[0].value_currency','USD');
CkJsonObject_UpdateString(json,'items[0].tariff_number','');
CkJsonObject_UpdateString(json,'items[0].origin_country','US');

CkHttp_SetRequestHeader(http,'Authorization','ShippoToken <API_TOKEN>');
CkHttp_SetRequestHeader(http,'Content-Type','application/json');

resp := CkHttpResponse_Create();
success := CkHttp_HttpJson(http,'POST','https://api.goshippo.com/customs/declarations/',json,'application/json',resp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

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

object_created := CkJsonObject__stringOf(jResp,'object_created');
object_updated := CkJsonObject__stringOf(jResp,'object_updated');
object_id := CkJsonObject__stringOf(jResp,'object_id');
object_owner := CkJsonObject__stringOf(jResp,'object_owner');
object_state := CkJsonObject__stringOf(jResp,'object_state');
address_importer := CkJsonObject__stringOf(jResp,'address_importer');
certify_signer := CkJsonObject__stringOf(jResp,'certify_signer');
certify := CkJsonObject_BoolOf(jResp,'certify');
non_delivery_option := CkJsonObject__stringOf(jResp,'non_delivery_option');
contents_type := CkJsonObject__stringOf(jResp,'contents_type');
contents_explanation := CkJsonObject__stringOf(jResp,'contents_explanation');
exporter_reference := CkJsonObject__stringOf(jResp,'exporter_reference');
importer_reference := CkJsonObject__stringOf(jResp,'importer_reference');
invoice := CkJsonObject__stringOf(jResp,'invoice');
commercial_invoice := CkJsonObject_BoolOf(jResp,'commercial_invoice');
license := CkJsonObject__stringOf(jResp,'license');
certificate := CkJsonObject__stringOf(jResp,'certificate');
notes := CkJsonObject__stringOf(jResp,'notes');
eel_pfc := CkJsonObject__stringOf(jResp,'eel_pfc');
aes_itn := CkJsonObject__stringOf(jResp,'aes_itn');
disclaimer := CkJsonObject__stringOf(jResp,'disclaimer');
incoterm := CkJsonObject__stringOf(jResp,'incoterm');
metadata := CkJsonObject__stringOf(jResp,'metadata');
test := CkJsonObject_BoolOf(jResp,'test');
duties_payor := CkJsonObject__stringOf(jResp,'duties_payor');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'items');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'items[i]');
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkHttpResponse_Dispose(resp);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

end;