Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loJson
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcStrVal
LOCAL lcObject_created
LOCAL lcObject_updated
LOCAL lcObject_id
LOCAL lcObject_owner
LOCAL lcObject_state
LOCAL lcAddress_importer
LOCAL lcCertify_signer
LOCAL lnCertify
LOCAL lcNon_delivery_option
LOCAL lcContents_type
LOCAL lcContents_explanation
LOCAL lcExporter_reference
LOCAL lcImporter_reference
LOCAL lcInvoice
LOCAL lnCommercial_invoice
LOCAL lcLicense
LOCAL lcCertificate
LOCAL lcNotes
LOCAL lcEel_pfc
LOCAL lcAes_itn
LOCAL lcDisclaimer
LOCAL lcIncoterm
LOCAL lcMetadata
LOCAL lnTest
LOCAL lcDuties_payor
LOCAL i
LOCAL lnCount_i
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = 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"
* }
* ]
* }
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("contents_type","MERCHANDISE")
loJson.UpdateString("non_delivery_option","RETURN")
loJson.UpdateBool("certify",1)
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('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpJson("POST","https://api.goshippo.com/customs/declarations/",loJson,"application/json",loResp)
IF (lnSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
RELEASE loResp
CANCEL
ENDIF
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0
? "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
CANCEL
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")
lnCertify = 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")
lnCommercial_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")
lnTest = 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