# TrackSort — Tracking Number Validator & Normalizer (`kopachelli/tracksort`) Actor

Detect the carrier, validate the format and normalize a batch of shipment tracking numbers — UPS, FedEx, DHL Express and USPS. One dataset item per number; no live tracking lookups, pay per event.

- **URL**: https://apify.com/kopachelli/tracksort.md
- **Developed by:** [Khristian Kopachelli](https://apify.com/kopachelli) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 processed tracking numbers

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## TrackSort — Shipment Tracking Number Normalizer

Give the Actor a batch of shipment tracking numbers. For each one it detects
the carrier, validates the format against that carrier's documented rules and
returns a normalized form — one dataset item per number.

**No live tracking lookups.** TrackSort never contacts a carrier, uses no
proxies and makes no outbound requests at all: it is pure format
classification, so runs are fast and cheap. Live status is deliberately out of
scope (see `docs/PRD.md` §9).

### Supported carriers (v1)

| Carrier id | Carrier | Format rule |
|---|---|---|
| `ups` | UPS | `1Z` + 16 alphanumeric characters |
| `fedex` | FedEx | 12, 15, 20 or 22 digits |
| `dhl` | DHL Express | 10 or 11 digits |
| `usps` | USPS | 20–22 digits |

Each rule cites its public source and verification date in `src/carriers.ts`.
Where two carriers' formats genuinely overlap — a 20- or 22-digit number fits
both USPS IMpb and FedEx, and FedEx Ground Economy legitimately carries USPS
numbers — the Actor does not guess: the item gets `carrier: null`,
`valid: true`, an `ambiguous-carrier` issue and both ids in `alternates`.

### Input

```json
{
    "trackingNumbers": [
        "1Z 999-AA1 0123 4567 84",
        "123456789012",
        "9400 1118 9922 3197 4284 9",
        "not-a-tracking-number"
    ],
    "carriers": ["ups", "fedex", "dhl", "usps"],
    "includeUnknown": true,
    "maxItems": 1000
}
```

- `trackingNumbers` — required, up to 10,000 entries.
- `carriers` — optional allow-list; excluded carriers are reported as
  `filtered-carrier:<id>` issues, never silently dropped.
- `includeUnknown` — default `true`: numbers matching no carrier format still
  get an item (`carrier: null`, `valid: false`). Set `false` to skip *those*
  unbilled; numbers that match a format — including filter-excluded and
  ambiguous matches — are always delivered with their issues disclosed.
- `maxItems` — process at most this many numbers per run (default 1,000,
  max 10,000); the rest are reported as truncated.

### Output

One dataset item per number:

```json
{
    "input": "1Z 999-AA1 0123 4567 84",
    "carrier": "ups",
    "carrierName": "UPS",
    "valid": true,
    "normalized": "1Z999AA10123456784",
    "checkDigitValid": null,
    "confidence": "high",
    "issues": []
}
```

- `normalized` — uppercase, spaces/dashes/dots stripped.
- `checkDigitValid` — `null` when the carrier publishes no public check-digit
  algorithm. Never guessed.
- `issues` — machine-readable: `unknown-carrier`, `no-allowed-carrier`,
  `ambiguous-carrier`, `filtered-carrier:<id>`, `bad-charset`,
  `check-digit-failed`, `empty`, `truncated-input`.
- `alternates` — every carrier id whose format matched the number (including
  filter-excluded ones), in carrier-table order. With a single winner it lists
  the other matches; with `ambiguous-carrier` or `no-allowed-carrier` it lists
  all of them.

A run summary (counts, stop reason) is stored as `OUTPUT` in the key-value
store.

### Pricing

Pay per event: `tracksort-number` per processed number, plus the standard
`apify-actor-start`. The `apify-default-dataset-item` event is **not** priced.
Numbers dropped by `includeUnknown: false` are not charged.

### Limits

Up to 10,000 numbers per run (`maxItems`). Numbers over 128 characters are
truncated and flagged `truncated-input` (raw inputs over 4,096 characters are
rejected). Pure computation — typical runs finish in seconds. Tracking numbers
are treated as customer data: logs carry hashes only, never full numbers.

# Actor input Schema

## `trackingNumbers` (type: `array`):

The tracking numbers to classify, one string per number. Separators (spaces, dashes, dots) are stripped; letters are uppercased.

## `carriers` (type: `array`):

Optional allow-list of carrier ids that may win attribution: ups, fedex, dhl, usps. Empty or absent means all supported carriers. Numbers matching only an excluded carrier still produce an item (carrier null, valid true, filtered-carrier:<id> issue); when several allowed carriers match, carrier is null with an ambiguous-carrier issue and both ids in alternates.

## `includeUnknown` (type: `boolean`):

When false, numbers that match no carrier format at all produce no dataset item and are not charged. Numbers that match a format — including filter-excluded and ambiguous matches — still produce items with their issues disclosed. Default true: every number gets an item, including honest unknown-carrier results.

## `maxItems` (type: `integer`):

Process at most this many numbers per run. Numbers beyond the cap are reported as truncated and are not charged.

## Actor input object example

```json
{
  "trackingNumbers": [
    "1Z999AA10123456784",
    "123456789012",
    "1234567890",
    "9400111899223197428490",
    "not-a-tracking-number"
  ],
  "carriers": [],
  "includeUnknown": true,
  "maxItems": 1000
}
```

# Actor output Schema

## `items` (type: `string`):

One item per tracking number: detected carrier, validity, normalized form, check-digit result, confidence and issues.

## `summary` (type: `string`):

How the run ended: numbers received, per-status counts, why it stopped.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "trackingNumbers": [
        "1Z999AA10123456784",
        "123456789012",
        "1234567890",
        "9400111899223197428490",
        "not-a-tracking-number"
    ],
    "carriers": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("kopachelli/tracksort").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "trackingNumbers": [
        "1Z999AA10123456784",
        "123456789012",
        "1234567890",
        "9400111899223197428490",
        "not-a-tracking-number",
    ],
    "carriers": [],
}

# Run the Actor and wait for it to finish
run = client.actor("kopachelli/tracksort").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "trackingNumbers": [
    "1Z999AA10123456784",
    "123456789012",
    "1234567890",
    "9400111899223197428490",
    "not-a-tracking-number"
  ],
  "carriers": []
}' |
apify call kopachelli/tracksort --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,kopachelli/tracksort"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Sm78RVvobEthPRQzy/builds/ufckjXgcBhchQsKNJ/openapi.json
