Skip to main content

JSONCargo

Blog

How to Track Containers in Python and Node.js using API

Tracking containers programmatically is one of the easiest ways to automate logistics workflows, monitor shipments, and keep your systems updated in real time. With the JsonCargo API, you can retrieve detailed container information using a simple request and integrate it directly into your application.

In this guide, we’ll walk through how to track containers using both Python and Node.js.

Introducing the Endpoint: Get Container Details

To get container details, you’ll use the following endpoint:

GET http://api.jsoncargo.com/api/v1/containers/{tracking_number}?shipping_line={shipping_line_name}

Required parameters

  • tracking_number: The container number (e.g. MEDU9091004)

  • shipping_line: The shipping line name (e.g. MSC, MAERSK, CMA_CGM)

Headers

x-api-key: YOUR_API_KEY

Each shipping line must match the correct API name. For example:

  • MSC

  • MAERSK

  • HAPAG_LLOYD

  • ONE

  • EVERGREEN

Example Response:

When the request is successful, you’ll receive structured JSON data including:

  • Container status

  • Origin and destination

  • ETA and timestamps

  • Vessel and voyage details

This makes it easy to plug directly into your system, dashboards, or alerts.

Tracking Containers in Python:

Here’s a simple Python example using the requests library:

				
					import requests
API_KEY = "YOUR_API_KEY"
tracking_number = "MEDU9091004"
shipping_line = "MSC"
url = f"http://api.jsoncargo.com/api/v1/containers/{tracking_number}?shipping_line={shipping_line}"
headers = {
    "x-api-key": API_KEY
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
    data = response.json()
    print("Container Status:", data["data"]["container_status"])
    print("Current Location:", data["data"]["last_location"])
    print("ETA:", data["data"]["eta_final_destination"])
else:
    print("Error:", response.status_code, response.text)
				
			

The script sends a GET request to the API and extracts key fields such as container status, location, and estimated arrival time. Since the response is in JSON, it’s easy to parse and use.

Tracking Containers in Node.js:

Now, let’s do the same in Node.js using axios:

				
					import requests
API_KEY = "YOUR_API_KEY"
tracking_number = "MEDU9091004"
shipping_line = "MSC"
url = f"http://api.jsoncargo.com/api/v1/containers/{tracking_number}?shipping_line={shipping_line}"
headers = {
    "x-api-key": API_KEY
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
    data = response.json()
    print("Container Status:", data["data"]["container_status"])
    print("Current Location:", data["data"]["last_location"])
    print("ETA:", data["data"]["eta_final_destination"])
else:
    print("Error:", response.status_code, response.text)
				
			

Potential Errors:

The API may return different responses depending on the situation:

  • 404 Container not found → Invalid tracking number

  • 404 Prefix not found → Shipping line or prefix not recognized

  • 429 Too many requests → Rate limit exceeded

  • 500 Internal Server Error → Temporary issue

If you encounter a Prefix Not Found error, it may simply mean the container prefix isn’t yet in the database. In that case, reach out to support to have it added.

Tracking containers in Python or Node.js is straightforward with the JsonCargo API. With minimal setup, you can retrieve detailed shipment data and integrate it into your systems.

Adding container-based testing on top ensures your integration is reliable, scalable, and ready for production from day one.