Sample code for 30+ languages & platforms
Lua

Shippo Track Individual Shipments

See more Shippo Examples

Demonstrates how to submit an individual tracking request for a single shipment.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()

-- Implements the following CURL command:

-- curl https://api.goshippo.com/tracks/usps/92701902416755000000000015 \
--     -H "Authorization: ShippoToken <API_TOKEN>"

http:set_request_header("Authorization", "ShippoToken <API_TOKEN>")

local sbResponseBody = chilkat.StringBuilder.new()
local success = http:quick_get_sb("https://api.goshippo.com/tracks/usps/92701902416755000000000015", sbResponseBody)
if not success then
    print(http.last_error_text)
    return
end

local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(http.last_header)
    print("Failed.")
    return
end

-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)

-- {
--   "object_state": "VALID",
--   "status": "SUCCESS",
--   "object_created": "2014-11-29T16:31:19.512Z",
--   "object_updated": "2014-11-29T16:31:19.512Z",
--   "object_id": "5695ae3a5eda41ba9abdbf347fd545f3",
--   "object_owner": "test@goshippo.com",
--   "test": false,
--   "rate": "693ea14a541f44e090291b929c171d5a",
--   "tracking_number": "9102969010383081813033",
--   "tracking_status": "DELIVERED",
--   "eta": "2014-11-24T00:00:00Z",
--   "tracking_url_provider": "https:\/\/tools.usps.com\/go\/TrackConfirmAction_input?origTrackNum=9102969010383081813033",
--   "label_url": "https:\/\/shippo-delivery-east.s3.amazonaws.com\/5695ae3a5eda41ba9abdbf347fd545f3.pdf?Signature=AyiitLq2g%2F2R9fjboCTVxi5z7JQ%3D&Expires=1534873886&AWSAccessKeyId=AKIAJGLCC5MYLLWIG42A",
--   "commercial_invoice_url": null,
--   "messages": [
--   ],
--   "order": "ca760ef0099040b4a2b7feec827bca88",
--   "metadata": "",
--   "parcel": "e0de043b2f7f4b6d8e6f23ad69641cc1",
--   "billing": {
--     "payments": [
--     ]
--   }
-- }

-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON

local object_state = jResp:string_of("object_state")
local status = jResp:string_of("status")
local object_created = jResp:string_of("object_created")
local object_updated = jResp:string_of("object_updated")
local object_id = jResp:string_of("object_id")
local object_owner = jResp:string_of("object_owner")
local test = jResp:bool_of("test")
local rate = jResp:string_of("rate")
local tracking_number = jResp:string_of("tracking_number")
local tracking_status = jResp:string_of("tracking_status")
local eta = jResp:string_of("eta")
local tracking_url_provider = jResp:string_of("tracking_url_provider")
local label_url = jResp:string_of("label_url")
local commercial_invoice_url = jResp:string_of("commercial_invoice_url")
local order = jResp:string_of("order")
local metadata = jResp:string_of("metadata")
local parcel = jResp:string_of("parcel")
local i = 0
local count_i = jResp:size_of_array("messages")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("billing.payments")
while i < count_i do
    jResp.i = i
    i = i + 1
end