Chilkat Online Tools

TCL / ShipEngine Walkthrough / Track using a label ID

Back to Collection Items

load ./chilkat.dll

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

set http [new_CkHttp]

CkHttp_SetRequestHeader $http "API-Key" "{{API_KEY}}"

set sbResponseBody [new_CkStringBuilder]

set success [CkHttp_QuickGetSb $http "https://api.shipengine.com/v1/labels/se-123456/track" $sbResponseBody]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttp_get_LastStatus $http]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttp_lastHeader $http]
    puts "Failed."
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

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

# {
#   "tracking_number": "9405511899564298877610",
#   "status_code": "NY",
#   "status_description": "Not Yet In System",
#   "carrier_status_code": "-2147219283",
#   "carrier_status_description": "A status update is not yet available for this tracking number.  More information will become available when USPS receives the tracking information, or when the package is received by USPS.",
#   "ship_date": null,
#   "estimated_delivery_date": null,
#   "actual_delivery_date": null,
#   "exception_description": null,
#   "events": null
# }

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

set tracking_number [CkJsonObject_stringOf $jResp "tracking_number"]
set status_code [CkJsonObject_stringOf $jResp "status_code"]
set status_description [CkJsonObject_stringOf $jResp "status_description"]
set carrier_status_code [CkJsonObject_stringOf $jResp "carrier_status_code"]
set carrier_status_description [CkJsonObject_stringOf $jResp "carrier_status_description"]
set ship_date [CkJsonObject_stringOf $jResp "ship_date"]
set estimated_delivery_date [CkJsonObject_stringOf $jResp "estimated_delivery_date"]
set actual_delivery_date [CkJsonObject_stringOf $jResp "actual_delivery_date"]
set exception_description [CkJsonObject_stringOf $jResp "exception_description"]
set events [CkJsonObject_stringOf $jResp "events"]

delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp

Curl Command

curl -X GET
	-H "API-Key: {{API_KEY}}"
https://api.shipengine.com/v1/labels/se-123456/track

Postman Collection Item JSON

{
  "name": "Track using a label ID",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.shipengine.com/v1/labels/{{label_id}}/track",
      "protocol": "https",
      "host": [
        "api",
        "shipengine",
        "com"
      ],
      "path": [
        "v1",
        "labels",
        "{{label_id}}",
        "track"
      ]
    },
    "description": "If you created the shipping label using ShipEngine, then tracking a package is even easier. No need to specify the `carrier_code` and `tracking_number`. All you need is the `label_id`."
  },
  "response": [
    {
      "name": "Track using a label ID",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.shipengine.com/v1/labels/{{label_id}}/track",
          "protocol": "https",
          "host": [
            "api",
            "shipengine",
            "com"
          ],
          "path": [
            "v1",
            "labels",
            "{{label_id}}",
            "track"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Wed, 18 Sep 2019 18:53:59 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json; charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "531"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "https://www.shipengine.com"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "x-shipengine-requestid",
          "value": "853bc684-6123-43aa-91ab-5ce1a8da908b"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"tracking_number\": \"9405511899564298877610\",\n    \"status_code\": \"NY\",\n    \"status_description\": \"Not Yet In System\",\n    \"carrier_status_code\": \"-2147219283\",\n    \"carrier_status_description\": \"A status update is not yet available for this tracking number.  More information will become available when USPS receives the tracking information, or when the package is received by USPS.\",\n    \"ship_date\": null,\n    \"estimated_delivery_date\": null,\n    \"actual_delivery_date\": null,\n    \"exception_description\": null,\n    \"events\": null\n}"
    }
  ]
}