> 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/stock-transfer-api/modification-request.md).

# Modification Request — 出庫内容の修正依頼

入庫検品中（`progress = receiving`）に「出庫内容を見直したい」ときに立てる **修正依頼**のサブリソースです。修正依頼を開くと、その移動の **受領更新がロック**され（[receive](/lmile-docs/stock-transfer-api/stock-transfer.md#post-apiroutingstock-transferreceive) が `modification_requested_locked` で拒否）、見直しが済んだら **完了**（受領を再開）または **取消**（破棄して受領を再開）します。1 つの移動に同時に開ける依頼は 1 件です。

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

> 移動そのもののライフサイクル（作成 → 承認 → 出庫 → 入庫）は [Stock Transfer](/lmile-docs/stock-transfer-api/stock-transfer.md) を参照してください。修正依頼は入庫検品中だけに関わるワークフローで、棚・在庫は動かしません（実数量は receive の受領数で確定します）。

## エンドポイント

| Method | Path                                                        | 用途                 |
| ------ | ----------------------------------------------------------- | ------------------ |
| `POST` | `/api/routing/stock-transfer/modification-request`          | 修正依頼を起票（受領をロック）    |
| `POST` | `/api/routing/stock-transfer/modification-request/complete` | 修正依頼を完了（受領を再開）     |
| `POST` | `/api/routing/stock-transfer/modification-request/delete`   | 修正依頼を取消・破棄（受領を再開）  |
| `GET`  | `/api/routing/stock-transfer/modification-requests`         | 修正依頼の一覧            |
| `GET`  | `/api/routing/stock-transfer/modification-request`          | 指定した移動の最新の修正依頼 1 件 |

### 状態の流れ

```
（入庫検品中 receiving のみ）
modificationRequest=none ─[create]─▶ requested ─[complete]─▶ completed
                                        │                        │
                                        └─[delete]─▶ none         └─[create]─▶ requested （再依頼可）
```

* `requested`（依頼中）の間は受領更新がロックされます。
* `complete` で `completed`（依頼済み・受領再開）、`delete` で `none`（破棄・受領再開）になります。
* 検品中に別の不整合が見つかれば `completed` から再度 `create` して `requested` に戻せます（再依頼）。

***

## `POST` /api/routing/stock-transfer/modification-request

修正依頼を起票します。**入庫検品中（`progress = receiving`）のときだけ**開けます。起票時点の明細内容をスナップショットとして記録します。

### リクエスト

```json
{
  "shop": "demo-store.myshopify.com",
  "stockTransferId": "0f1e2d3c-…",
  "reason": "数量差異のため要確認"
}
```

### ボディパラメータ

| パラメータ             | 型             |  必須 | 説明                         |
| ----------------- | ------------- | :-: | -------------------------- |
| `shop`            | string        |  ✓  | 店舗ドメイン（API キーで呼ぶ場合は省略できます） |
| `stockTransferId` | string (uuid) |  ✓  | 対象の移動 ID                   |
| `reason`          | string        |     | 依頼理由（任意）                   |

### レスポンス

```json
{
  "ok": true,
  "stockTransferId": "0f1e2d3c-…",
  "modificationRequestId": "mr-1234…",
  "modificationRequest": "requested"
}
```

### 挙動・冪等性

* **入庫検品中のみ**: `progress` が `receiving` でなければ `not_receiving` を返します。
* **1 件だけ**: 既に依頼が開いている（`requested`）移動への再起票は `modification_request_already_open` を返します。
* 起票すると受領更新がロックされます（[receive](/lmile-docs/stock-transfer-api/stock-transfer.md#post-apiroutingstock-transferreceive) が `modification_requested_locked`）。

***

## `POST` /api/routing/stock-transfer/modification-request/complete

開いている修正依頼を完了します（`requested → completed`）。受領更新のロックが解除されます。

### ボディパラメータ

| パラメータ             | 型             |  必須 | 説明                         |
| ----------------- | ------------- | :-: | -------------------------- |
| `shop`            | string        |  ✓  | 店舗ドメイン（API キーで呼ぶ場合は省略できます） |
| `stockTransferId` | string (uuid) |  ✓  | 対象の移動 ID                   |

### レスポンス

```json
{ "ok": true, "stockTransferId": "0f1e2d3c-…", "modificationRequest": "completed" }
```

* 開いている依頼が無ければ `no_open_modification_request` を返します。

***

## `POST` /api/routing/stock-transfer/modification-request/delete

開いている修正依頼を取り消して破棄します（`requested → none`）。受領更新のロックが解除されます。依頼行は破棄済み（`deleted`）として記録に残ります。

### ボディパラメータ

| パラメータ             | 型             |  必須 | 説明                         |
| ----------------- | ------------- | :-: | -------------------------- |
| `shop`            | string        |  ✓  | 店舗ドメイン（API キーで呼ぶ場合は省略できます） |
| `stockTransferId` | string (uuid) |  ✓  | 対象の移動 ID                   |

### レスポンス

```json
{ "ok": true, "stockTransferId": "0f1e2d3c-…", "modificationRequest": "none" }
```

* 開いている依頼が無ければ `no_open_modification_request` を返します。

***

## `GET` /api/routing/stock-transfer/modification-requests

修正依頼の一覧を取得します。

### クエリパラメータ

| パラメータ             |  必須 | 説明                                                                      |
| ----------------- | :-: | ----------------------------------------------------------------------- |
| `shop`            |  ✓  | 店舗ドメイン（API キーで呼ぶ場合は省略できます）                                              |
| `status`          |     | 状態で絞り込み（`requested` / `completed` / `deleted`。**既定 `requested`** = 依頼中） |
| `stockTransferId` |     | 特定の移動に絞り込み                                                              |

### レスポンス

```json
{
  "ok": true,
  "items": [
    {
      "id": "mr-1234…",
      "stockTransferId": "0f1e2d3c-…",
      "status": "requested",
      "reason": "数量差異のため要確認",
      "linesSnapshot": [
        { "lineId": "…", "barcode": "1234567890123", "quantity": 5, "shippedQuantity": 5,
          "receivedAcceptedQuantity": 0, "receivedRejectedQuantity": 0 }
      ],
      "requestedAt": "2026-07-09T03:00:00.000Z",
      "completedAt": null,
      "deletedAt": null,
      "transferProgress": "receiving",
      "transferIdentificationNo": "TR-2026-0001"
    }
  ]
}
```

新しい順（`requestedAt` 降順）で返します。各行に依頼時点の明細スナップショット（`linesSnapshot`）と、紐づく移動のサマリ（`transferProgress` / `transferIdentificationNo`）を付与します。

## `GET` /api/routing/stock-transfer/modification-request

指定した移動の **最新の修正依頼 1 件**を取得します。

### クエリパラメータ

| パラメータ  |  必須 | 説明                         |
| ------ | :-: | -------------------------- |
| `shop` |  ✓  | 店舗ドメイン（API キーで呼ぶ場合は省略できます） |
| `id`   |  ✓  | 移動 ID（`stockTransferId`）   |

### レスポンス

```json
{ "ok": true, "modificationRequest": { "id": "mr-1234…", "stockTransferId": "0f1e2d3c-…", "status": "requested", "…": "…" } }
```

* `id`（クエリ）は **移動の ID**（`stockTransferId`）です。その移動の最新の依頼を 1 件返します。
* 該当が無ければ `404` + `error_kind: not_found`。

***

## エラー

エンドポイント固有:

| `error_kind`                        | Status | エンドポイント              | 意味                            |
| ----------------------------------- | :----: | -------------------- | ----------------------------- |
| `not_receiving`                     |  `422` | modification-request | 入庫検品中（`receiving`）でないため起票できない |
| `modification_request_already_open` |  `422` | modification-request | 既に開いている依頼がある（1 件のみ）           |
| `no_open_modification_request`      |  `422` | complete / delete    | 完了・取消できる開いた依頼が無い              |
| `not_found`                         |  `404` | 各エンドポイント / get       | 指定 ID の移動 / 依頼が存在しない          |

共通エラー（`401` / `400` / `403` / `405` / `500` / `503`）は [Error Codes](/lmile-docs/reference/error-codes.md) を参照。ボディのバリデーション失敗は `400` + `invalid_input`（`details[]` 付き）です。

## データモデル

* `sot.lm_stock_transfer_modification_requests` — 修正依頼（`status`: `requested` / `completed` / `deleted`・`reason`・依頼時点の明細スナップショット `lines_snapshot`・`requested_by_staff_user_id`・各遷移時刻）。1 伝票に active（`requested`）は 1 件（partial unique index）。移動ヘッダ `sot.lm_stock_transfers.modification_request` と同期します（詳細は [Stock Transfer データモデル](https://lmile.gitbook.io/lmile-docs/stock-transfer-api/pages/20DiVRGUzk7qNxNjt17I#データモデル)）。


---

# 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/stock-transfer-api/modification-request.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.
