> For the complete documentation index, see [llms.txt](https://lmile.gitbook.io/lmile-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lmile.gitbook.io/lmile-docs/fulfillment-api/print-label.md).

# Print Label — ラベル手動再印刷

Storage に保存済みの出荷ラベル PDF を、出荷元の print server（[Dispatch Config](https://lmile.gitbook.io/lmile-docs/fulfillment-api/pages/bGOYICmcj4SdTpefqrDg#actionprint-ラベル物理印刷) の `action=print`）へ**再送**します。紙詰まり・印刷失敗・プリンター不調からの回収用です。[Retry Label](/lmile-docs/fulfillment-api/address-recovery.md) と違い**キャリア API を再呼び出ししません** = 追跡番号は変わりません。

> **Base URL** `https://api.lmile.io` · **認証** `x-ingest-secret` ヘッダー または operator JWT（`Authorization: Bearer`）（[詳細](/lmile-docs/getting-started/authentication.md)） · `shop` はリクエストボディに含めます（API キーで呼ぶ場合は省略できます）

> `/api/routing/shipment/print-label` は機械間 secret（`x-ingest-secret`）と倉庫スタッフの operator JWT のどちらでも呼べます（系統はヘッダの有無で明示判別。[詳細](https://lmile.gitbook.io/lmile-docs/fulfillment-api/pages/7cB70I8yeRnMpvcdLkNu#routing-write-の-2-系統認証)）。operator JWT 経由は操作スタッフを記録します。

> ラベル生成成功時の自動印刷（[Fulfillment](/lmile-docs/fulfillment-api/fulfillment.md)）が失敗すると `sot.lm_fulfillment_shipments.last_print_error` に記録されます。本 API で保存済み PDF を再印刷してください。ラベル**再発行**（[Address Recovery](/lmile-docs/fulfillment-api/address-recovery.md) の `retry-label` / `autoRetryLabel`）の成功時は印刷イベントが自動配信されるため本 API の呼び出しは不要です — 本 API は紙詰まり等の**手動再印刷専用**です。

## エンドポイント

| Method | Path                                | 用途                              |
| ------ | ----------------------------------- | ------------------------------- |
| `POST` | `/api/routing/shipment/print-label` | 保存済みラベル PDF の手動再印刷（キャリア再呼び出しなし） |

***

## `POST` /api/routing/shipment/print-label

### リクエスト

```http
POST https://api.lmile.io/api/routing/shipment/print-label
x-ingest-secret: {INGEST_SECRET}
Content-Type: application/json
```

```json
{
  "shop": "demo-store.myshopify.com",
  "sourceSystem": "shopify",
  "externalOrderRef": "1001"
}
```

### ボディパラメータ

| パラメータ                               | 型                |  必須 | 説明                                                  |
| ----------------------------------- | ---------------- | :-: | --------------------------------------------------- |
| `shop`                              | string           |  ✓  | 店舗ドメイン（API キーで呼ぶ場合は省略できます）                          |
| `routingOrderId`                    | string (uuid)    |  △  | 対象注文。無ければ `sourceSystem` + `externalOrderRef` で特定   |
| `sourceSystem` / `externalOrderRef` | string           |  △  | `routingOrderId` 未指定時に必須                            |
| `fromLocationId`                    | string\[] (uuid) |     | 対象出荷元を限定。**省略時は保存済みラベル（`label_pdf_path`）がある出荷元すべて** |

### レスポンス

```json
{
  "ok": true,
  "routingOrderId": "11111111-1111-1111-1111-111111111111",
  "printed": 1,
  "shipments": [
    { "fromLocationId": "a1b2c3d4-...", "action": "printed",
      "labelPdfPath": "demo-store.myshopify.com/1111.../a1b2c3d4.pdf" }
  ]
}
```

| フィールド                      | 説明                                                                                                                                      |
| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `printed`                  | 印刷送信に成功した出荷元数（`action: "printed"` の件数）                                                                                                  |
| `shipments[].action`       | `printed`（送信成功）/ `skipped`（対象外）/ `failed`（送信失敗）                                                                                         |
| `shipments[].reason`       | skip / fail 理由: `no_label_pdf`（保存済みラベルなし）/ `fulfillment_source_unresolved` / `no_print_config`（print 設定なし）/ `label_pdf_download_failed` |
| `shipments[].labelPdfPath` | 印刷した PDF の Storage パス（`shipping-labels` バケット）                                                                                           |
| `shipments[].error`        | `action=failed` 時の print server 応答（`last_print_error` に保存）                                                                              |

### 挙動・冪等性

* **対象**: `fromLocationId` 指定 > 省略時は `label_pdf_path` がある出荷元すべて。ラベル未生成の出荷元は `no_label_pdf` で skip します（本 API はラベルを生成しません。生成は [Fulfillment](/lmile-docs/fulfillment-api/fulfillment.md) / [Retry Label](/lmile-docs/fulfillment-api/address-recovery.md)）。
* **print 設定の解決キーは出荷元**（`action=label` と同じ。[Dispatch Config](/lmile-docs/configuration/dispatch-config.md)）。設定の無い出荷元は `no_print_config` で skip（silent skip しません）。
* **成功**: `label_printed_at` を更新し `last_print_error` をクリア。**失敗**: `last_print_error` を更新。
* **冪等性はありません**（呼ぶたびに物理印刷されます）。同じラベルを複数回 POST すると複数枚出力されます — 再印刷の意図的な操作としてのみ使用してください。

## エラー

エンドポイント固有:

| Status | 条件                    | レスポンス例                                                                                 |
| :----: | --------------------- | -------------------------------------------------------------------------------------- |
|  `400` | 注文の特定情報なし / バリデーション失敗 | `{ "ok": false, "error_kind": "invalid_input", "details": [...] }`                     |
|  `404` | 注文が存在しない              | `{ "ok": false, "error_kind": "order_not_found", "error": "routing order not found" }` |

共通エラー（`401` / `400` / `403` / `405` / `500` / `503`）は [Error Codes](/lmile-docs/reference/error-codes.md) を参照。

## データモデル

* `sot.lm_fulfillment_shipments` — 出荷元ごとの `label_pdf_path` / `label_printed_at` / `last_print_error`。再印刷はこの行を更新（[Fulfillment](/lmile-docs/fulfillment-api/fulfillment.md)）
* `sot.lm_location_dispatch_config.action = 'print'` — 出荷元 print server 設定（[Dispatch Config](/lmile-docs/configuration/dispatch-config.md)）
* ラベル PDF: Supabase Storage `shipping-labels`（private）の `{shop}/{routingOrderId}/{fromLocationId}.pdf`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://lmile.gitbook.io/lmile-docs/fulfillment-api/print-label.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
