# 最初のリクエスト

商品を 1 件登録し、在庫を設定して、販売による在庫変動を送る手順です。

> **Base URL** `https://api.lmile.io` · **認証** `x-ingest-secret` ヘッダー · `shop` はボディに含めます

## 1. 商品登録

```bash
curl -X POST https://api.lmile.io/api/ingest/products \
  -H "x-ingest-secret: $INGEST_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "shop": "demo-store.myshopify.com",
    "products": [{
      "barcode": "1234567890123",
      "product_name": "スマートフォンケース",
      "sku": "DEMO-CASE-001",
      "brand": "Demo Brand",
      "category_l1": "ケース",
      "current_price": 9800
    }]
  }'
```

```json
{ "ok": true, "created": 1, "updated": 0, "unchanged": 0, "errors_count": 0, "errors": [] }
```

## 2. 在庫設定（スナップショット / 絶対値）

```bash
curl -X POST https://api.lmile.io/api/ingest/inventory-snapshot \
  -H "x-ingest-secret: $INGEST_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "shop": "demo-store.myshopify.com",
    "source_system": "manual_api",
    "location_id": "YOUR_LOCATION_UUID",
    "lines": [
      { "barcode": "1234567890123", "on_hand_qty": 10, "available_qty": 10 }
    ]
  }'
```

```json
{ "ok": true, "lines_processed": 1, "lines_upserted": 1, "lines_unresolved": 0, "logs_written": 1, "unresolved": [] }
```

## 3. 販売による在庫変動（available / delta）

```bash
curl -X POST https://api.lmile.io/api/ingest/inventory-available \
  -H "x-ingest-secret: $INGEST_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "shop": "demo-store.myshopify.com",
    "source_system": "pos",
    "mode": "delta",
    "idempotency_key": "sale-0001",
    "location_id": "YOUR_LOCATION_UUID",
    "lines": [
      { "barcode": "1234567890123", "available_delta": -1 }
    ]
  }'
```

```json
{ "ok": true, "mode": "delta", "lines_updated": 1, "lines_clamped": 0, "lines_deduped": 0, "unresolved": [], "clamped": [] }
```

販売可能在庫が 10 → 9 に更新され、`inventory_update_logs` に `available_delta` イベントが記録されます。

## 次のステップ

* [Products API](/lmile-docs/ingestion-apis/products.md) — 全フィールドの詳細
* [Inventory Levels API](/lmile-docs/ingestion-apis/inventory-levels.md) — snapshot と available の詳細
* [Order Line Master API](/lmile-docs/ingestion-apis/order-line-master.md) — 受注明細
* [Data Model](/lmile-docs/reference/data-model.md) — テーブル構造


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lmile.gitbook.io/lmile-docs/getting-started/your-first-request.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
