Home → Blog

Shipment plans through Tianjin Xin Gang can change when port activity departs from its usual pattern, but a current vessel wait time is not available from this endpoint. By the end of this guide, you can request Tianjin’s port-activity indicator, read its reporting date and baseline ratio, and use it without mistaking lagged port-call data for live congestion.

What the Tianjin congestion endpoint measures

The endpoint GET /api/v1/port-congestion?port=Tianjin returns an IMF PortWatch-derived indicator for Tianjin Xin Gang. It compares the average daily port calls over the most recent seven days in the series with a 90-day baseline for the same port.

Illustration: API to Get Port Congestion at Tianjin Xin Gang

The data is typically lagged by approximately six to seven days rather than being live AIS. The sample response gives a broader four-to-eleven-day lag and explains that PortWatch republishes the daily series once a week. Check as_of on each result instead of assuming the response describes today.

The distinction between activity and congestion matters. In the sample’s methodology, congestion is a deprecated alias of activity; neither field measures vessel waiting or anchorage time. Lower-than-usual port calls can have more than one explanation, including a closure or vessels waiting offshore, so the indicator alone does not establish the cause.

Request Tianjin Xin Gang data

Send the port name in the port query parameter and authenticate with the X-API-Key header. Replace YOUR_API_KEY with your key before running the request. Guests can also make requests without a key, subject to 100 requests per day per IP.

curl -H "X-API-Key: YOUR_API_KEY" "https://freightpulsehq.com/api/v1/port-congestion?port=Tianjin"

The query uses Tianjin, while the result identifies the port as Tianjin Xin Gang. Keep that distinction when mapping the API result to the port name shown in a shipment-planning interface.

For further endpoint details, see the Documentation.

Read the response and its reporting date

The following is the supplied Tianjin response. Its values describe the sample’s reporting date, not a current port condition.

{
    "success": true,
    "data": {
        "results": [
            {
                "port": "Tianjin Xin Gang",
                "locode": null,
                "country": "China",
                "activity": "moderate",
                "congestion": "moderate",
                "as_of": "2026-11-20",
                "metrics": {
                    "recent_avg_portcalls_per_day": 25.9,
                    "baseline_avg_portcalls_per_day": 28.8,
                    "ratio_vs_baseline": 0.9
                }
            }
        ],
        "global_summary": {
            "ports_high_activity": 0,
            "ports_moderate_activity": 1,
            "ports_low_activity": 0,
            "ports_high_congestion": 0,
            "ports_moderate": 1,
            "ports_low": 0
        },
        "meta": {
            "source": "IMF PortWatch (portwatch.imf.org) - UN Global Platform AIS data",
            "data_lag_days": "4-11 (PortWatch republishes the daily series once a week; check as_of)",
            "methodology": "activity is port-call volume, not congestion: last 7 days' avg calls vs a 90-day baseline for the same port. low means fewer calls than usual, which can be a closure or ships waiting offshore. It does not measure vessel wait or anchorage time. congestion is a deprecated alias of activity."
        }
    },
    "meta": {
        "request_id": "71187e80-6b29-473a-8fec-ed00d64875db"
    }
}

Use success to check the response envelope, then read the Tianjin entry in data.results. The fields most useful to an integration are:

In this sample, the recent average is 25.9 calls per day against a baseline of 28.8, with a reported ratio of 0.9. Those values indicate activity below the baseline in the sample; they do not tell you how long a vessel waited. The locode is null, so an integration should not require it to be present.

The response contains two separate meta objects: data.meta describes the source, lag and methodology, while the outer meta contains a request identifier. Preserve that distinction if you log provenance alongside request diagnostics.

Call the endpoint from Python

This example uses Python’s standard library and the same URL and authentication header as the curl request. Replace YOUR_API_KEY before running it. It checks the envelope, handles an empty result list, and reads the fields needed to display the indicator with its date.

import json
import urllib.error
import urllib.request

url = "https://freightpulsehq.com/api/v1/port-congestion?port=Tianjin"
api_key = "YOUR_API_KEY"

request = urllib.request.Request(
url,
headers={"X-API-Key": api_key},
method="GET",
)

try:
with urllib.request.urlopen(request) as response:
payload = json.load(response)
except urllib.error.HTTPError as error:
raise SystemExit("API request failed with HTTP status: " + str(error.code))
except urllib.error.URLError as error:
raise SystemExit("Could not reach the API: " + str(error.reason))
except json.JSONDecodeError:
raise SystemExit("The API response was not valid JSON.")

if not isinstance(payload, dict) or payload.get("success") is not True:
raise SystemExit("The API did not report a successful response.")

data = payload.get("data")
if not isinstance(data, dict):
raise SystemExit("The response did not contain a data object.")

results = data.get("results")
if not isinstance(results, list) or not results:
raise SystemExit("No port result was returned.")

result = results[0]
if not isinstance(result, dict):
raise SystemExit("The port result was not an object.")

metrics = result.get("metrics")
if not isinstance(metrics, dict):
metrics = dict()

print("Port:", result.get("port"))
print("Activity:", result.get("activity"))
print("Congestion alias:", result.get("congestion"))
print("As of:", result.get("as_of"))
print("Recent calls per day:", metrics.get("recent_avg_portcalls_per_day"))
print("Baseline calls per day:", metrics.get("baseline_avg_portcalls_per_day"))
print("Ratio vs baseline:", metrics.get("ratio_vs_baseline"))

The code reads the first result because the supplied Tianjin response contains one. If your application depends on identifying the port, also check the returned port value before associating the result with a shipment. Missing fields print as None; treat them as unavailable rather than converting them to zero.

Keep the key out of source control in a deployed integration. The literal key value in the example is there so the authentication header is easy to locate and replace.

Use the indicator in a logistics workflow

Show the activity classification, ratio and as_of date together. A label such as “port-call activity relative to baseline” is more precise than presenting the value as a current vessel queue or an estimated delay. If an interface retains the congestion field for compatibility, explain that it is an alias of activity in the supplied methodology.

Cache the response if repeated reads would otherwise make unnecessary requests, but retain the source’s as_of date with the cached value. A newly fetched response can still contain an older observation, so the time your application fetched it is not a substitute for the reporting date. The supplied response does not specify a timezone or time of day for that date.

Use a change in the ratio as a signal to investigate, not as a standalone delay forecast. The two averages provide context for the ratio, while other operational information is needed to determine whether a particular vessel or shipment is waiting. The supplied example shows one result and does not establish pagination behavior; consult the documentation if your integration needs to handle results beyond the example.

FAQ

Is this a live Tianjin vessel-wait API?

No. The indicator comes from IMF PortWatch port-call data and is typically lagged by around six to seven days. It does not measure vessel wait or anchorage time.

What does a ratio below the baseline mean?

It means the recent average port-call volume is below the baseline average. It does not by itself identify the cause or quantify a shipment delay.

Can I request the data without an API key?

Yes. Guest access without a key is limited to 100 requests per day per IP. With a key, send it in the X-API-Key header.

Which field should I use: activity or congestion?

Use activity for the port-call classification. The supplied methodology describes congestion as a deprecated alias, not an independent measurement of waiting time.

Register to obtain an API key, then run the Tianjin request and display the returned activity, baseline ratio and reporting date together.