React Native
React Native
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 React Native Downloads
import { Http, HttpResponse, JsonObject, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = new 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"
// }
// ]
// }
const json = new 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');
const resp = new HttpResponse();
try {
await http.httpJsonAsync('POST', 'https://api.goshippo.com/customs/declarations/', json, 'application/json', resp);
} catch {
console.log(http.lastErrorText);
return;
}
const sbResponseBody = new StringBuilder();
resp.getBodySb(sbResponseBody);
const jResp = new JsonObject();
jResp.loadSb(sbResponseBody);
jResp.emitCompact = false;
console.log('Response Body:');
console.log(jResp.emit());
const respStatusCode = resp.statusCode;
console.log(`Response Status Code = ${respStatusCode}`);
if (respStatusCode >= 400) {
console.log('Response Header:');
console.log(resp.header);
console.log('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
let strVal = '';
const objectCreated = jResp.stringOf('object_created');
const objectUpdated = jResp.stringOf('object_updated');
const objectId = jResp.stringOf('object_id');
const objectOwner = jResp.stringOf('object_owner');
const objectState = jResp.stringOf('object_state');
const addressImporter = jResp.stringOf('address_importer');
const certifySigner = jResp.stringOf('certify_signer');
const nonDeliveryOption = jResp.stringOf('non_delivery_option');
const contentsType = jResp.stringOf('contents_type');
const contentsExplanation = jResp.stringOf('contents_explanation');
const exporterReference = jResp.stringOf('exporter_reference');
const importerReference = jResp.stringOf('importer_reference');
const invoice = jResp.stringOf('invoice');
const license = jResp.stringOf('license');
const certificate = jResp.stringOf('certificate');
const notes = jResp.stringOf('notes');
const eelPfc = jResp.stringOf('eel_pfc');
const aesItn = jResp.stringOf('aes_itn');
const disclaimer = jResp.stringOf('disclaimer');
const incoterm = jResp.stringOf('incoterm');
const metadata = jResp.stringOf('metadata');
const dutiesPayor = jResp.stringOf('duties_payor');
let i = 0;
const countI = jResp.sizeOfArray('items');
while (i < countI) {
jResp.i = i;
strVal = jResp.stringOf('items[i]');
i++;
}
}