Examples
Request examples in Node.js, Python, and Google Apps Script
This page shows how to retrieve tracking data for one number with GET /v2/tracking. Choose a language and replace YOUR_TOKEN with your API key.
Base URL for requests: https://tracking.timetocargo.com/v2.
More examples:
- Batch tracking — submit up to 500 numbers with
POST /v2/tracking/batchto create a tracking task. The API returns a task ID without waiting for tracking results. Retrieve its results later withGET /v2/tracking/batch. - Shipments — list tracked shipments, add or update a note, and archive or delete a record.
- Companies — get supported carriers, their SCAC codes, and available tracking types.
- Webhooks — receive tracking updates and verify their signatures.
Required query parameters: api_key, company (AUTO or a carrier SCAC code), and value (the number). Omit type (container, bl, or bk) for automatic detection.
To detect the number type automatically, omit type in GET /v2/tracking or an item’s track_number.type in POST /v2/tracking/batch. company remains required. Explicit container, bl, and bk retain the requested search mode; null, an empty string, and AUTO are invalid type values. Automatic detection returns one selected result, rather than a list of alternatives.
The response request echoes the original input. With automatic detection, request.track_number.type is absent; this field does not report the detected number type.
Container descriptions and ISO codes
Each container has two equipment fields:
type— a short description, for example40' High Cube Dry.iso_code— the confirmed ISO 6346 size/type code or group, for example45G1or45GP.
An unrecognized carrier label stays in type, with iso_code: null. Missing values and known non-container
values produce null in both fields. A group identifies the general equipment class; it does not confirm a
more detailed subtype. type shows the size and general equipment family; subtype details remain in iso_code. Use type for display and iso_code for code-based integrations.
Both API versions expose these fields. V1 single-container results use data.container; v1 batch results and
v2 use data.containers. Older stored results may omit iso_code, so clients should accept both missing and
null values. The meaning of type changes from a carrier label or code to a description when recognized.
Request example
The example tracks a container and prints the result status and shipment summary.
Node.js 18+ with global fetch.
// Request tracking data for one number and read the result.
// Set the API URL and request parameters.
const API_BASE = "https://tracking.timetocargo.com/v2";
const url = new URL(`${API_BASE}/tracking`);
url.searchParams.set("api_key", "YOUR_TOKEN");
url.searchParams.set("company", "AUTO");
url.searchParams.set("value", "MSDU8368827");
url.searchParams.set("type", "container");
const res = await fetch(url, { headers: { Accept: "application/json" } });
// Check the HTTP response before using the result.
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
// Read JSON; success and status describe the request result.
const body = await res.json();
if (body.success === false) throw new Error(body.status_description || body.status);
console.log(body.status, body.data?.summary ?? null);Error handling
Handle HTTP failures, honor 429, and inspect status even when HTTP is 200. Do not log the API key.
// Request tracking data for one number and read the result.
// Set the API URL and request parameters.
const API_BASE = "https://tracking.timetocargo.com/v2";
async function track({ token, company, value, type }) {
const url = new URL(`${API_BASE}/tracking`);
url.searchParams.set("api_key", token);
url.searchParams.set("company", company);
url.searchParams.set("value", value);
url.searchParams.set("type", type);
const res = await fetch(url, {
headers: { Accept: "application/json" },
signal: AbortSignal.timeout(90_000),
});
if (res.status === 429) {
const retryAfter = res.headers.get("Retry-After");
throw new Error(`Rate limited. Retry-After: ${retryAfter ?? "not provided"}`);
}
// Check the HTTP response before using the result.
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
// Read JSON; success and status describe the request result.
const body = await res.json();
if (body.status === "INFO_NOT_FOUND" && body.success === true) return null;
if (body.success === false || body.status !== "OK") {
throw new Error(body.status_description ?? body.status);
}
return body.data;
}
const data = await track({
token: process.env.TIMETOCARGO_API_KEY,
company: "AUTO",
value: "MSDU8368827",
type: "container",
});
const summary = data?.summary;
const locations = data?.locations ?? [];
const pol = summary?.pol?.location != null ? locations[summary.pol.location] : null;
const lastActualEvent = data?.containers?.[0]?.events?.find((event) => event.actual);
console.log({
company: summary?.company?.full_name,
departure: pol?.name,
lastActualEvent,
});See the API reference for response schemas and parameters.
Last updated on