Home → Blog

When a shipment is moving through Hong Kong, a congestion label without a date or methodology can be misleading. This guide shows how to request the HKHKG port-congestion record, read its activity and baseline fields, and use the result without treating lagged data as a live vessel wait time.

Request Hong Kong congestion data

Send a GET request to the port-congestion endpoint with port=HKHKG. The documented authentication header is X-API-Key; replace YOUR_API_KEY with your key before running the request.

Illustration: API to Get Port Congestion at Hong Kong
curl -H "X-API-Key: YOUR_API_KEY" "https://freightpulsehq.com/api/v1/port-congestion?port=HKHKG"

Guest requests without a key are also available, with a limit of 100 requests per day per IP. The keyed request above is the appropriate starting point for an integration that uses an API key.

The port identifier in the query is HKHKG. In the response sample, the same location appears in the locode field as HK HKG; account for that formatting difference if you validate or display the returned code.

Understand the response

The following is the provided response sample for Hong Kong. Its values describe the observation date in as_of; they should not be interpreted as the current state of the port.

{
    "success": true,
    "data": {
        "results": [
            {
                "port": "Hong Kong",
                "locode": "HK HKG",
                "country": "Hong Kong SAR",
                "activity": "moderate",
                "congestion": "moderate",
                "as_of": "2026-11-27",
                "metrics": {
                    "recent_avg_portcalls_per_day": 36.7,
                    "baseline_avg_portcalls_per_day": 37.7,
                    "ratio_vs_baseline": 0.97
                }
            }
        ],
        "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": "c85de63f-a875-49d5-a834-03b21cc8a63b"
    }
}

Check success, then read the Hong Kong record from data.results. The key fields for an integration are activity, congestion, as_of, and the values under metrics. The response methodology identifies congestion as a deprecated alias of activity, so prefer the activity field when describing what the measure represents.

The two average fields are expressed in port calls per day. recent_avg_portcalls_per_day is the recent seven-day average, while baseline_avg_portcalls_per_day is the 90-day baseline for the same port. ratio_vs_baseline is a dimensionless comparison of those averages, not a duration, a vessel count waiting offshore, or a freight rate.

In the sample, the recent average is 36.7 calls per day against a baseline of 37.7, with a reported ratio of 0.97. Those are sample observations, not a promise about the value returned by a later request. The sample also includes global_summary and source methodology, but a Hong Kong display can use the individual record rather than treating summary counts as a measurement of waiting vessels.

Call the endpoint from Python

This example uses Python’s standard library and calls the same URL as the curl request. It checks the response envelope, finds the Hong Kong record, and reads the fields needed for a dated activity display.

import json
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen

url = "https://freightpulsehq.com/api/v1/port-congestion?port=HKHKG"
request = Request(url, headers={"X-API-Key": "YOUR_API_KEY"})

try:
with urlopen(request) as response:
payload = json.load(response)
except HTTPError as exc:
raise SystemExit("HTTP request failed: " + str(exc.code))
except URLError:
raise SystemExit("Could not reach the port-congestion service")
except (ValueError, UnicodeDecodeError):
raise SystemExit("Response was not valid JSON")

if not isinstance(payload, dict) or payload.get("success") is not True:
raise SystemExit("The API did not return 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):
raise SystemExit("The response did not contain a results list")

hong_kong = next(
(
item for item in results
if isinstance(item, dict)
and item.get("locode") in ("HK HKG", "HKHKG")
),
None,
)
if hong_kong is None:
raise SystemExit("No Hong Kong record was returned")

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

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

Replace YOUR_API_KEY before running the example. For a deployed service, load the key from your secret-management mechanism rather than committing it to source control or exposing it in browser code.

The example prints missing optional values as None rather than turning them into zero. In a user interface, render a missing value as unavailable; a missing ratio or label is not evidence of low activity.

Interpret the data in a shipping workflow

The source is IMF PortWatch, based on the daily port-call series described in the response metadata. It is lagged by roughly six to seven days, rather than being a live AIS view. The sample metadata gives a broader four-to-eleven-day lag because PortWatch republishes the daily series weekly, so check as_of on each returned record instead of assuming a fixed delay.

The sample’s as_of value is a calendar date, not a timestamp with a timezone. Display it as the supplied date and do not append a time or timezone that the response has not provided. Keep the observation date separate from the time your application retrieved or displayed the record.

Activity compares port-call volume with the port’s own baseline. A lower-than-usual volume can have different explanations, including a closure or vessels waiting offshore; the metric cannot establish which explanation applies. Likewise, a moderate label does not tell an operator how long a particular vessel will wait or whether it has a berth.

For a shipment dashboard, pair the activity label with as_of and the ratio so that a reader can see both the classification and its dated context. If a workflow requires vessel-specific arrival, anchorage, berth, or waiting-time information, this response alone does not provide it.

Build a reliable integration

Cache the result if your application serves repeated views of Hong Kong activity, but preserve the returned as_of alongside the cached values. Because the upstream series is republished weekly and its lag varies, a new API fetch does not necessarily mean the underlying observation date has advanced.

Choose a refresh policy that fits your shipping workflow and guest request limit, rather than polling as though this were a live feed. If a refresh fails, distinguish a previously cached observation from a fresh response and continue to show its observation date. Do not silently relabel an older record as current.

Validate both the top-level success indicator and the returned record before updating downstream systems. A successful HTTP connection alone does not establish that the payload contains a Hong Kong result. The code also handles an empty results list and a missing metrics object without manufacturing measurements.

Keep the original numeric values when storing or passing the metrics to another component. If you round values for display, do not recompute the reported ratio from rounded display numbers and present it as the source value. The sample provides no pagination controls, so this integration reads the returned results list rather than assuming a pagination scheme.

For endpoint details and any changes to the response contract, consult the Documentation.

FAQ

Is this a live Hong Kong port-congestion feed?

No. The IMF PortWatch series is lagged, typically by roughly six to seven days. The provided response metadata describes a possible four-to-eleven-day lag and recommends checking as_of.

Does the congestion field give vessel waiting time?

No. The response describes congestion as a deprecated alias of activity, which is based on port-call volume relative to a baseline. It does not measure vessel wait or anchorage time.

What does the baseline ratio mean?

ratio_vs_baseline compares the recent seven-day average of port calls per day with the 90-day average for Hong Kong. It has no time unit and should not be converted into an estimated wait.

Can I request the data without an API key?

Yes. Guest access without a key is limited to 100 requests per day per IP. The examples above use the documented X-API-Key header instead.

Why does the response code contain a space?

The request uses HKHKG, while the sample returns the location code as HK HKG. Treat those as formatting differences when matching the response to the requested Hong Kong port.

To start using the keyed request in your shipping integration, Register, then run the curl request and verify the returned as_of date before displaying the result.