> 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/shipment-unsecure.md).

# Shipment Unsecure — 確保済みの解除

誤って確保済みにした単位（[Units](/lmile-docs/fulfillment-api/units.md)）を、確保する前の状態へ戻します。店舗が現物を押さえていないのに確保済みにしてしまった、というときに使います。

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

## エンドポイント

| Method | Path                             | 用途             |
| ------ | -------------------------------- | -------------- |
| `POST` | `/api/routing/shipment/unsecure` | 確保済みの単位を確保前へ戻す |

***

## `POST` /api/routing/shipment/unsecure

指定 shipment の確保済みの単位を、確保前へ戻します。`unitId` を送るとその 1 単位だけ、省略するとこの出荷の確保済みの単位すべてが対象です。

### リクエスト

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

```json
{
  "shop": "demo-store.myshopify.com",
  "shipmentId": "11494bc4-f45f-4d0b-9d68-fd26c1a503ec",
  "unitId": "8052c57a-d258-4e22-b4eb-8346210e236c"
}
```

### ボディパラメータ

| パラメータ        | 型             |  必須 | 説明                          |
| ------------ | ------------- | :-: | --------------------------- |
| `shop`       | string        |  ✓  | 店舗ドメイン（API キーで呼ぶ場合は省略できます）  |
| `shipmentId` | string (uuid) |  ✓  | 対象 shipment。同一 shop に実在すること |
| `unitId`     | string (uuid) |     | 戻す単位。省略するとこの出荷の確保済みの単位すべて   |

### レスポンス

```json
{
  "ok": true,
  "shipmentId": "11494bc4-f45f-4d0b-9d68-fd26c1a503ec",
  "unsecured": 1
}
```

| フィールド       | 説明                                   |
| ----------- | ------------------------------------ |
| `unsecured` | 今回のリクエストで確保前へ戻した単位数。既に確保前だった単位は数えません |

### 挙動・冪等性

* **戻せるのは「確保済みで、まだ集荷していない」単位だけ**です。集荷済みの単位、確保のときに棚から出した単位、転送されてくる荷物の出荷、出荷元変更・返送の途中の単位は `409` で拒否します。
* **戻り先は、確保する前の状態です**。引き当て済みだった単位は引き当て済み（`allocated`）へ、在庫が無く引き当てられないまま確保した単位は引き当て前（`unallocated`）へ戻ります。
* 対象に戻せない単位が 1 つでもあれば、**何も変えずに** `409` を返します。一部だけ戻ることはありません。
* 戻すのは確保の印だけです。引き当て先・出荷元・在庫数・配送ラベル・追跡番号は変わりません。
* 戻した単位は、もう一度 [確保](/lmile-docs/fulfillment-api/units.md) できます。出荷は、全単位が確保済みになるまで確保済みになりません。
* **お届け状況は「準備中」のまま変わりません**。準備中のお知らせメールを送ったあとに戻しても、取り消しのメールは送りません。確保し直しても、同じメールがもう一度送られることはありません。
* **再送は冪等です**: 既に確保前の単位はそのまま維持し、`unsecured: 0` を返します。そのまま再送して構いません。
* 戻した操作は出荷メモに記録されます。

## エラー

エンドポイント固有:

| Status | 条件                             | レスポンス例                                                                                                     |
| :----: | ------------------------------ | ---------------------------------------------------------------------------------------------------------- |
|  `404` | `shipmentId` が同一 shop に存在しない   | `{ "ok": false, "error_kind": "shipment_not_found", "error": "shipment not found for shop" }`              |
|  `404` | `unitId` がこの出荷に無い（取消済みの単位を含む）  | `{ "ok": false, "error_kind": "unit_not_found", "error": "unit not found on shipment" }`                   |
|  `409` | 出荷済み・取消済みなど、確保済み・確保前以外の出荷      | `{ "ok": false, "error_kind": "invalid_state", "error": "shipment status 'shipped' cannot be unsecured" }` |
|  `409` | 単位が確保済みでない（売越しの対応中・倉庫間移動中など）   | `{ "ok": false, "error_kind": "unit_not_secured", "unitId": "..." }`                                       |
|  `409` | 単位が集荷済み                        | `{ "ok": false, "error_kind": "unit_already_picked", "unitId": "..." }`                                    |
|  `409` | 確保のときに棚から出した単位（棚の在庫数が既に減っています） | `{ "ok": false, "error_kind": "shelf_already_released", "unitId": "..." }`                                 |
|  `409` | 転送されてくる荷物の出荷（引き当てを持たない出荷）      | `{ "ok": false, "error_kind": "no_allocation_leg", "unitId": "..." }`                                      |
|  `409` | 出荷元変更・返送の途中の単位                 | `{ "ok": false, "error_kind": "transfer_in_progress", "unitId": "..." }`                                   |

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

## データモデル

* `sot.lm_fulfillment_units.status` / `secured` / `secured_at` / `secured_by_staff_user_id` — 単位の確保。本 API は `status` を確保する前の値（`allocated` / `unallocated`）に戻し、残りを空にします。
* `sot.lm_fulfillment_shipments.status` / `secured_at` — 出荷が確保済みだった場合は、確保する前の値（`allocated` / `unallocated`）に戻します。
* `sot.lm_shipment_memos` — 操作の記録（`event_code = "unsecured"`）。


---

# 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/shipment-unsecure.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.
