> 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/configuration/source-members.md).

# Source Members — 出荷元マッピング

出荷元（fulfillment source）に、引き当て対象の在庫ロケーションを紐付けます。ルーティング（[Routing](/lmile-docs/routing-api/orders.md)）はこのマッピングで解決されたメンバー在庫ロケーション内だけで引き当てます。設定・解除・取得を API で行えます。

> **Base URL** `https://api.lmile.io` · **認証** `x-ingest-secret` ヘッダー（[詳細](/lmile-docs/getting-started/authentication.md)） · set/detach は `shop` をボディ、取得はクエリに含めます（省略するとキーのアカウント）

> マッピングのキーは `(shop, inventoryLocationId)` = **在庫ロケーションは1出荷元のみに属する（1出荷元 : N在庫）**。既に別の出荷元に紐づく在庫ロケーションを set すると、その出荷元へ**付け替え**られます。

## エンドポイント

| Method | Path                                 | 用途                  |
| ------ | ------------------------------------ | ------------------- |
| `POST` | `/api/routing/source-members`        | マッピング設定（upsert）     |
| `POST` | `/api/routing/source-members/detach` | マッピング解除（物理削除）       |
| `GET`  | `/api/routing/source-members`        | マッピング状況の取得（ラベル付き一覧） |

***

## `POST` /api/routing/source-members

出荷元↔在庫ロケーションのマッピングを upsert します。

### リクエスト

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

```json
{
  "shop": "demo-store.myshopify.com",
  "fulfillmentSourceLocationId": "11111111-1111-1111-1111-111111111111",
  "inventoryLocationId": "22222222-2222-2222-2222-222222222222",
  "priorityRank": 1,
  "isActive": true,
  "onlyBarcodes": ["4900000000011"]
}
```

### ボディパラメータ

| パラメータ                         | 型                 |  必須 | 説明                                                                                                     |
| ----------------------------- | ----------------- | :-: | ------------------------------------------------------------------------------------------------------ |
| `shop`                        | string            |     | 店舗ドメイン（省略するとキーのアカウント）                                                                                  |
| `fulfillmentSourceLocationId` | string (uuid)     |  ✓  | 出荷元 location（shop 内に実在すること）                                                                            |
| `inventoryLocationId`         | string (uuid)     |  ✓  | 紐付ける在庫ロケーション（shop 内に実在。出荷元自身も指定可 = 自己在庫を引き当て対象にする）                                                     |
| `priorityRank`                | number            |     | 販売可能在庫・地域一致が同点の場合の並び順（昇順・任意。未設定は最後）。出荷元自身の在庫は SKU 拠点オーバーライド（`force_first` / `force_only`）がある場合を除き常に最優先 |
| `isActive`                    | boolean           |     | 有効フラグ（default `true`。`false` で論理無効化）                                                                   |
| `onlyBarcodes`                | string\[] \| null |     | この在庫ロケーションを対象にする商品のバーコード。配列 = その商品だけ / `[]` = どの商品も対象にしない / `null` = 全商品。省略すると既存の値を変えない（新規は全商品）        |

### レスポンス

```json
{ "ok": true, "id": "...", "shop": "demo-store.myshopify.com",
  "fulfillmentSourceLocationId": "1111...", "inventoryLocationId": "2222...",
  "priorityRank": 1, "isActive": true, "onlyBarcodes": ["4900000000011"], "enqueued": 12 }
```

### 挙動

* **upsert キー**: `(shop, inventoryLocationId)`。同じ在庫ロケーションを別の出荷元で set すると**出荷元が付け替わる**（1:N 整合）。
* `isActive: false` でマッピングを残したまま無効化（ルーティングの候補から外れる）。完全に消す場合は detach。
* **対象の商品を絞る**: `onlyBarcodes` を送ると、その在庫ロケーションは指定した商品だけ出荷元の合算在庫に足され、引き当ての候補になります。指定していない商品は、在庫があっても合算にも引き当てにも入りません。
  * 例: 新しい店舗を `"onlyBarcodes": []` で追加すると、合算在庫は変わりません（`enqueued: 0`）。その後 `"onlyBarcodes": ["4900000000011"]` で送り直すと、その 1 商品だけ店舗の在庫が合算に足されます。
  * 全商品に広げるときは `"onlyBarcodes": null` を送ります。
* **合算在庫の再同期**: マッピングの変更で出荷元の合算販売可能在庫が変わるため、設定後に**影響を受けた出荷元（新規/付け替えの場合は新・旧の両出荷元）の合算 available を再計算し、変動分を** [**Source Inventory webhook**](/lmile-docs/webhooks/source-inventory.md) **として発火**します（外部在庫ミラーへ反映）。`enqueued` は起票した在庫変動イベント数（合算が変わらなければ `0`）。

***

## `POST` /api/routing/source-members/detach

マッピングを物理削除します（在庫ロケーション基準）。

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

```json
{ "shop": "demo-store.myshopify.com", "inventoryLocationId": "22222222-2222-2222-2222-222222222222" }
```

| パラメータ                 | 型             |  必須 | 説明                    |
| --------------------- | ------------- | :-: | --------------------- |
| `shop`                | string        |     | 店舗ドメイン（省略するとキーのアカウント） |
| `inventoryLocationId` | string (uuid) |  ✓  | 解除する在庫ロケーション          |

レスポンス: `{ "ok": true, "shop": "...", "inventoryLocationId": "...", "deleted": 1, "enqueued": 8 }`（`deleted` は削除件数。該当無しは `0`）。

解除すると外した在庫ロケーション分だけ出荷元の合算が減るため、**旧出荷元の合算 available を再計算し変動分を** [**Source Inventory webhook**](/lmile-docs/webhooks/source-inventory.md) **として発火**します。**最後のメンバーを外した場合も合算は `0` に補正**されます（外部在庫ミラーが在庫過大のまま固着しません）。`enqueued` は起票した在庫変動イベント数。

***

## `GET` /api/routing/source-members

shop（任意で出荷元）のマッピング状況をラベル付きで取得します。

```http
GET https://api.lmile.io/api/routing/source-members?shop=demo-store.myshopify.com
x-ingest-secret: {INGEST_SECRET}
```

| クエリ                           |  必須 | 説明                      |
| ----------------------------- | :-: | ----------------------- |
| `shop`                        |     | 店舗ドメイン（省略するとキーのアカウント）   |
| `fulfillmentSourceLocationId` |     | 指定するとその出荷元のマッピングのみに絞り込み |

### レスポンス

```json
{
  "ok": true,
  "shop": "demo-store.myshopify.com",
  "count": 2,
  "mappings": [
    { "id": "...", "fulfillmentSourceLocationId": "1111...", "fulfillmentSourceLabel": "MFCセンター東京",
      "inventoryLocationId": "2222...", "inventoryLocationLabel": "BONAVENTURA 日本橋三越本店",
      "priorityRank": 1, "isActive": true, "onlyBarcodes": null }
  ]
}
```

***

## エラー

エンドポイント固有:

| Status | 条件                                                                                      | レスポンス例                                                                                                   |
| :----: | --------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|  `400` | 必須欠落 / 非 UUID / source==inventory / `shop` クエリ無し / `onlyBarcodes` が文字列の配列でも `null` でもない | `{ "ok": false, "error": "inventoryLocationId (uuid) required" }`                                        |
|  `422` | location が shop 内に存在しない                                                                 | `{ "ok": false, "error_kind": "location_unresolved", "error": "inventory location not found for shop" }` |

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

## データモデル

* `sot.lm_fulfillment_source_members` — 出荷元 → 在庫ロケーション 紐付け（`UNIQUE shop + inventory_location_id` で 1出荷元:N在庫を強制。自己参照 = 出荷元自身をメンバーにする自己在庫は許可）
* 読み取り view（管理 UI 用）: `public.lm_v_fulfillment_source_members`


---

# 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/configuration/source-members.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.
