> ## Documentation Index
> Fetch the complete documentation index at: https://docs.goshippo.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Shippo is a multi-carrier shipping API. For agent integrations that execute shipping operations (rates, labels, tracking, address validation, customs), connect the hosted Shippo MCP server at https://mcp.shippo.com (per-user OAuth; setup at /guides/mcp-server). To search and read this documentation from an agent, a docs search MCP is available at https://docs.goshippo.com/mcp. Shipping workflow knowledge (agent skills and a knowledge pack) is published at https://github.com/goshippo/ai. For REST integrations start at /guides/api-quickstart; test mode uses shippo_test_ API keys.

# Automations

> [!NOTE]
>
> The Automations API is in **beta**. Request and response shapes may change without the notice period that applies to generally available Shippo endpoints, and they are not yet covered by the `SHIPPO-API-VERSION` header. Breaking changes are announced to enrolled accounts before they ship — pin nothing in production you can't redeploy.

## Buy the right label in one call

Shipping a parcel through the Shippo API takes four steps today: create a shipment, fetch rates, compare them against your own logic, then buy the label. The Automations API collapses that into one request. You send the shipment, Shippo applies your rule, selects the rate, and buys the label.

One call to `POST https://api.goshippo.com/automations/labels` does all four. Authenticate with `Authorization: ShippoToken <API_TOKEN>`. A missing or invalid token returns `401`. If Automations isn't enabled for your account, every endpoint returns `403`; contact [Shippo API Support](https://support.goshippo.com/).

> [!WARNING]
>
> **This spends money.** A successful live request charges your Shippo account for the selected rate, and it cannot be undone through this API — refunds go through the [Refunds API](https://docs.goshippo.com/api-reference/refunds/create-a-refund.md). Send `dry_run: true` to see which rate your rule would select, with no purchase and no charge.

## The rule in beta

In this beta, every account is provisioned with exactly **one rule**, named `default`, which selects the lowest-cost eligible rate for the shipment. The rule is created for you the first time you call the API — there's nothing to configure, and there's no endpoint for authoring or editing rules yet. Customer-defined rules are planned for a later release.

### Service levels the rule never selects

The rule never selects the service levels below, even when one is the cheapest rate. Each is limited to certain contents, senders, or mail types that Automations can't check. A label bought for a shipment that doesn't qualify still goes through, and USPS can charge postage due or return the package later.

| Service level | Why it's excluded |
| :- | :- |
| `usps_media_mail` | Only for educational media, such as books and recordings. Eligibility depends on what's in the package. |
| `usps_library_mail` | Only for items mailed between qualifying institutions, such as libraries, schools, and museums. Eligibility depends on the sender, recipient, and contents. |
| `usps_first_class_mail_letter` | For letters and flat envelopes, not parcels. |

These rates are removed before the rule runs, so they don't appear in the decision's `rule_trace`. If every rate returned for a shipment is excluded, the request ends in `no_match` with `reason.code` `all_rates_excluded`. To ship with one of these service levels, buy the label directly with [Create a shipping label](https://docs.goshippo.com/api-reference/transactions/create-a-shipping-label.md).

## The request

The request body is the standard Shippo [`POST /shipments`](https://docs.goshippo.com/api-reference/shipments/create-a-new-shipment) create body, plus `dry_run`. Any field that endpoint accepts is passed through unchanged, so the shipment you send is the shipment Shippo rates and buys. Addresses and parcels can be sent inline or as existing Shippo object IDs.

Two things are required on every call:

* **`Idempotency-Key` header** — a client-generated key, 1–255 characters, that makes retries safe. More on this below.
* **`address_from`, `address_to`, `parcels`** — the minimum a shippable shipment needs.

```sh theme={null}
curl --request POST \
  --url https://api.goshippo.com/automations/labels \
  --header 'Authorization: ShippoToken <API_TOKEN>' \
  --header 'Content-Type: application/json' \
  --header 'Idempotency-Key: 6f1e2d3c-4b5a-6978-8a9b-0c1d2e3f4a5b' \
  --data '{
    "address_from": {
      "name": "Acme",
      "street1": "215 Clayton St",
      "city": "San Francisco",
      "state": "CA",
      "zip": "94117",
      "country": "US"
    },
    "address_to": {
      "name": "Casey",
      "street1": "965 Mission St",
      "city": "San Francisco",
      "state": "CA",
      "zip": "94103",
      "country": "US"
    },
    "parcels": [
      {
        "length": "10",
        "width": "8",
        "height": "4",
        "distance_unit": "in",
        "weight": "2",
        "mass_unit": "lb"
      }
    ]
  }'
```

## It's asynchronous

The purchase doesn't happen inside the request. `POST /automations/labels` responds `202` immediately with a `request_id` and a `poll_url`, then does the work — fetch rates → evaluate your rule → purchase — in the background.

```json theme={null}
{
  "request_id": "b3b8f6b0-1a2b-4c3d-9e4f-5a6b7c8d9e0f",
  "status": "processing",
  "poll_url": "/automations/labels/b3b8f6b0-1a2b-4c3d-9e4f-5a6b7c8d9e0f"
}
```

You receive the final outcome two ways:

* **Polling — the source of truth.** Call `GET /automations/labels/{request_id}` (the `poll_url`, a relative path) and read `status`. Use it to confirm an outcome, to reconcile a missed webhook, or on its own if you don't run a webhook endpoint. While `status` is `processing`, the response carries a display-only `message` tracking the stage ("Fetching rates.", "Evaluating rules.", "Purchasing label."); don't branch on it. Polling is read-only and safe to repeat.
* **Webhooks — an optional push.** Subscribe to the `automations_label_resolved` event to be notified when a request reaches a terminal state, so you don't have to poll as often. Failed deliveries aren't retried, so confirm outcomes by polling. See [Webhooks](#webhooks).

Both channels return the same body shape — see [Outcomes](#outcomes).

## Outcomes

A successful poll returns HTTP `200` for every outcome. Branch on `status`:

| `status` | Meaning | Terminal? |
| :- | :- | :- |
| `processing` | Still working. Keep polling. | No |
| `purchased` | The label was bought. The response includes `tracking_number`, `label_url`, and `transaction_id`. | Yes |
| `dry_run_completed` | A rate was selected; nothing was purchased. | Yes |
| `no_match` | No eligible rate was selected; nothing was purchased. See `reason`. | Yes |
| `failed` | Processing ended unsuccessfully. See `error`. | Yes |

> [!WARNING]
>
> **Detect a real purchase with `status == "purchased"`, not `dry_run == false`.** The `dry_run` field echoes what you sent; it is not the purchase outcome. Always branch on `status`.

A purchased response looks like this:

```json theme={null}
{
  "request_id": "b3b8f6b0-1a2b-4c3d-9e4f-5a6b7c8d9e0f",
  "status": "purchased",
  "dry_run": false,
  "test": false,
  "shipment_id": "5e40ead7cffe4cc1ad45108696162e42",
  "transaction_id": "9b2d4f6a8c0e4a1b3d5f7a9c1e3b5d7f",
  "tracking_number": "9400111899223197428490",
  "label_url": "https://shippo-delivery.s3.amazonaws.com/2f8b6d1e4a9c4f3b8e7d5a1c6b9e0f24.pdf",
  "selected_rate": {
    "rate_id": "c4e8a2f6d0b94c17a3e5f7b9d1c3e5a7",
    "carrier": "USPS",
    "service_level": "usps_priority",
    "amount": "7.35"
  },
  "created_at": "2026-09-03T18:04:10Z"
}
```

To track the parcel, call [Retrieve a shipping label](https://docs.goshippo.com/api-reference/transactions/retrieve-a-shipping-label.md) with `transaction_id`. The label includes `tracking_status` and the carrier's tracking link in `tracking_url_provider`.

`selected_rate.carrier` is the selected rate's carrier name (its `provider`, such as `USPS`), and `selected_rate.service_level` is its service-level token, such as `usps_priority`.

### When nothing is selected: `no_match`

`no_match` is a non-error outcome — your rule and fallback simply didn't pick a rate. The `reason.code` tells you why. Branch on the code, not the message, and tolerate codes not listed here.

| `reason.code` | What happened |
| :- | :- |
| `no_match` | No rate was selected by your rule or fallback. |
| `all_rates_excluded` | Rates came back, but none were eligible for automatic selection. See [Service levels the rule never selects](#service-levels-the-rule-never-selects). |
| `no_rates_returned` | No rates were returned for the shipment. |

### When it breaks: `failed`

Only `failed` responses include an `error`. Branch on `error.code` and tolerate additional codes — the catalog will grow.

```json theme={null}
{
  "request_id": "b3b8f6b0-1a2b-4c3d-9e4f-5a6b7c8d9e0f",
  "status": "failed",
  "dry_run": false,
  "test": false,
  "error": {
    "code": "address_validation_failed",
    "message": "An address could not be validated. Check the address details."
  },
  "created_at": "2026-09-03T18:04:10Z"
}
```

> [!WARNING]
>
> **A `failed` automation may have an unconfirmed purchase.** When `error.code` is `pipeline_dropped_during_purchase` or `pipeline_dropped_purchase_unresolved`, the purchase couldn't be confirmed. Check the account or [list your shipping labels](https://docs.goshippo.com/api-reference/transactions/list-all-shipping-labels.md) before retrying, so you don't buy a duplicate label. `transaction_failed` means the purchase failed, so no label was bought.

## Webhooks

Webhooks are a convenience on top of polling: they tell you when a request finishes so you don't have to poll as often. Subscribe to the **`automations_label_resolved`** event in the [Shippo API Portal](https://portal.goshippo.com/api-config/webhooks) or with the [Webhooks API](https://docs.goshippo.com/tracking/creating-webhooks.md) — an `all` wildcard subscription receives it too. The SDK event enums don't include it, so SDK users subscribe through the API.

**One event, every outcome.** Each request produces one `automations_label_resolved` event, when it reaches a terminal state — `purchased`, `dry_run_completed`, `no_match`, or `failed`. In-progress states never fire.

**Delivery.** Delivery is best effort. If a delivery fails, including a timeout or a `5XX` from your endpoint, Shippo doesn't retry it; the retries in [Expected webhook behavior](https://docs.goshippo.com/tracking/webhooks.md#expected-webhook-behavior) don't apply to this event. Deliveries can arrive out of order, and the same event can occasionally be delivered more than once. Polling is the source of truth: if a webhook and a poll disagree, trust the poll.

**The payload is the terminal result, field for field.** The event's `data` is exactly what `GET /automations/labels/{request_id}` returns for that outcome — same `status`, `reason`, `error`, and `selected_rate`. Read the outcome from `data.status`, and detect a dry run from `data.dry_run` (never from `status`). The rule trace, `poll_url`, and any event id are not included.

Accounts on API version 2017-03-29 or older receive the result itself, without the `event`, `test`, and `data` wrapper, so read `status`, `dry_run`, and `request_id` at the top level.

```json theme={null}
{
  "event": "automations_label_resolved",
  "test": false,
  "data": {
    "request_id": "b3b8f6b0-1a2b-4c3d-9e4f-5a6b7c8d9e0f",
    "status": "purchased",
    "dry_run": false,
    "test": false,
    "shipment_id": "5e40ead7cffe4cc1ad45108696162e42",
    "transaction_id": "9b2d4f6a8c0e4a1b3d5f7a9c1e3b5d7f",
    "tracking_number": "9400111899223197428490",
    "label_url": "https://shippo-delivery.s3.amazonaws.com/2f8b6d1e4a9c4f3b8e7d5a1c6b9e0f24.pdf",
    "selected_rate": {
      "rate_id": "c4e8a2f6d0b94c17a3e5f7b9d1c3e5a7",
      "carrier": "USPS",
      "service_level": "usps_priority",
      "amount": "7.35"
    },
    "created_at": "2026-09-03T18:04:10Z"
  }
}
```

**Verify and dedupe.** Check the `Shippo-Auth-Signature` on every delivery before trusting it (see [Webhook security](https://docs.goshippo.com/tracking/webhook-security.md)). Treat `data.request_id` as the idempotency key, and reconcile anything you didn't receive by polling `GET /automations/labels` for terminal requests with no matching delivery. The `test` field reflects whether the request used a test token and is unrelated to `dry_run`.

**A successful purchase also fires `transaction_created`.** Because Automations buys the label through the normal Transactions path, a `purchased` request triggers your existing `transaction_created` webhook in addition to `automations_label_resolved`. If you subscribe to both, you'll receive two events for one successful purchase — dedupe on `request_id`.

## Dry runs

Send `dry_run: true` to evaluate your rule and select a rate **without purchasing or charging**. The request runs through rate-fetching and rule evaluation, then stops — it ends in `dry_run_completed` (or `no_match` / `failed` if selection couldn't complete). Automated callers should dry-run an unfamiliar shipment shape before running it live.

`dry_run` must be a genuine JSON boolean (no string coercion). Dry runs are **never deduplicated** — each one starts a fresh evaluation, even with a repeated `Idempotency-Key`.

## Idempotency

The `Idempotency-Key` header is required on every request. For a **live** request, repeating the same key returns a pointer to the original request instead of creating a duplicate purchase, which makes it safe to retry after a network blip. Keys don't expire and the request body isn't compared, so a repeated key always returns the original request, even if the body changed or the original request `failed`. To try again after a `failed` outcome, use a new key. **Dry runs are never deduplicated.**

## The decision record — "why this carrier, why this price"

Every request keeps a decision record. `GET /automations/labels/{request_id}/decision` returns the rule that matched, the rate selected, the facts the engine evaluated, and the full rule trace — the audit answer to "why this carrier, why this price," without building and instrumenting your own rate-comparison logic.

```json theme={null}
{
  "request_id": "b3b8f6b0-1a2b-4c3d-9e4f-5a6b7c8d9e0f",
  "test": false,
  "status": "purchased",
  "dry_run": false,
  "shipment_id": "5e40ead7cffe4cc1ad45108696162e42",
  "transaction_id": "9b2d4f6a8c0e4a1b3d5f7a9c1e3b5d7f",
  "tracking_number": "9400111899223197428490",
  "label_url": "https://shippo-delivery.s3.amazonaws.com/2f8b6d1e4a9c4f3b8e7d5a1c6b9e0f24.pdf",
  "created_at": "2026-09-03T18:04:10Z",
  "evaluated_at": "2026-09-03T18:04:12Z",
  "label_processed_at": "2026-09-03T18:04:20Z",
  "decision": {
    "decision_log_id": "c1d2e3f4-5a6b-7c8d-9e0f-1a2b3c4d5e6f",
    "auto_provisioned": true,
    "estimate_available": false,
    "matched_rule_name": "default",
    "matched_priority": 1,
    "fallback_triggered": false,
    "selected_rate": {
      "rate_id": "c4e8a2f6d0b94c17a3e5f7b9d1c3e5a7",
      "carrier": "USPS",
      "service_level": "usps_priority",
      "amount": "7.35"
    },
    "facts_input": {
      "planned_ship_date": null
    },
    "ruleset_snapshot": {
      "rule_set_id": "d4e5f6a7-b8c9-4d0e-9f1a-2b3c4d5e6f70",
      "fallback": {
        "strategy": "min_field",
        "field": "cost"
      },
      "rules": [
        {
          "priority": 1,
          "rule_id": "e5f6a7b8-c9d0-4e1f-8a2b-3c4d5e6f7a81",
          "name": "default",
          "version": 1,
          "condition_groups": [],
          "action": {
            "strategy": "min_field",
            "field": "cost"
          }
        }
      ]
    },
    "rule_trace": [
      {
        "priority": 1,
        "rule_id": "e5f6a7b8-c9d0-4e1f-8a2b-3c4d5e6f7a81",
        "rule_name": "default",
        "rule_version": 1,
        "matched": true,
        "short_circuited": false,
        "condition_results": [],
        "selection": {
          "strategy": "min_field",
          "field": "cost",
          "winner_id": "c4e8a2f6d0b94c17a3e5f7b9d1c3e5a7",
          "values_considered": [
            {
              "rate_id": "c4e8a2f6d0b94c17a3e5f7b9d1c3e5a7",
              "value": "7.35"
            },
            {
              "rate_id": "7a1c3e5b9d2f4a6c8e0b1d3f5a7c9e2b",
              "value": "9.85"
            }
          ],
          "tiebreaker_applied": false,
          "tiebreaker_resolved_by": null,
          "tied_candidates": []
        }
      }
    ]
  }
}
```

The decision is written once and never changes. It's available as soon as evaluation completes — including while a live purchase is still `processing`. If evaluation hasn't written a decision yet, `/decision` returns `409`; an unknown `request_id` returns `404`.

Because beta runs a single always-matching rule, `fallback_triggered` is always `false`. The `matched_priority` and `fallback_triggered` fields describe ordering and fallback behavior that become meaningful once customer-defined rules ship.

## Listing requests

`GET /automations/labels` lists your label-purchase requests, newest first — a management view for dashboards and reconciliation. It returns a page of flat summaries plus a `next` link (an opaque cursor; `null` on the last page).

Filter with `shipment_id`, `tracking_number`, `status`, and `dry_run`. Filters are AND-combined and preserved across pages by the `next` link. Page size is 1–100 (default 25).

## Before you go live

* **Subscribe to `automations_label_resolved`**, verify the `Shippo-Auth-Signature`, and dedupe on `request_id`. Failed deliveries aren't retried, so poll to reconcile anything you miss; polling is the source of truth.
* **Dry-run first.** Validate an unfamiliar shipment shape with `dry_run: true` before spending money on it.
* **Send a fresh `Idempotency-Key` per logical purchase.** Reuse it verbatim when retrying the same request after a network error so a blip can't double-charge you, and use a new key to try again after a `failed` outcome.
* **Branch on `status` and the `code` fields**, and tolerate codes you don't recognize — reason and error catalogs will grow.
* **Treat a `failed` outcome as possibly purchased** when `error.code` is `pipeline_dropped_during_purchase` or `pipeline_dropped_purchase_unresolved`; check your labels before retrying.
* **Expect change.** Shapes may shift during beta and aren't covered by `SHIPPO-API-VERSION`.

## What's not here yet

No custom or multi-rule authoring and no rule-editing endpoints. These are planned for later releases.


## Related topics

- [Buy a label using your automation rules](https://docs.goshippo.com/api-reference/automations/buy-a-label-using-your-automation-rules.md)
- [Glossary](https://docs.goshippo.com/api-concepts/glossary.md)
- [List label-purchase requests](https://docs.goshippo.com/api-reference/automations/list-label-purchase-requests.md)
