クイックスタート
組織の API キーを使って、REST API v1 を最初に呼ぶまでの手順です。資格情報の確認(whoami)、見積の一覧と取得、顧客の登録、見積の下書きの作成を、curl・Python(requests)・Node.js(fetch)で示します。
現在この機能は限定提供中です。利用ご希望の場合は お問い合わせ からご相談ください。
前提
- 組織の管理者が API キーを発行できること。発行の画面は API キーと外部アプリの接続 を参照してください
- 手順ごとに必要な権限は次のとおりです。全部を試すなら、
read・data:write・piiを付けたキーを発行してください
| 手順 | 必要な権限 |
|---|---|
| 2. 疎通を確かめる | 有効なキーならどれでも |
| 3. 見積を一覧する・4. 見積を 1 件取得する | read・write・data:write のどれか。宛名などを受け取るには pii も |
| 5. 顧客を登録する | data:write と pii |
| 6. 見積の下書きを作る | data:write と pii |
- Python の例は
requestsを使います(pip install requests)。Node.js の例は 18 以降の組み込みのfetchを使い、ES モジュール(.mjs)として実行します
1. API キーを用意する
管理者が画面の「設定 → データ連携 → API キー」でキーを発行します。キーは sk_live_ で始まる 51 文字の文字列で、発行した直後に 1 回だけ全文が表示されます。 表示されたキーを環境変数に入れておきます。
export SOKUMITSU_API_KEY="sk_live_..."
キーはソースコードやリポジトリに書かないでください。漏れた恐れがあるときは、画面ですぐに失効させます(認証と権限)。
2. 疎通を確かめる
GET /api/v1/whoami は、資格情報がどの組織のもので、どの権限を持つかを返します。最初にこれを呼んでください。
curl -s https://api.sokumitsu.com/api/v1/whoami \
-H "Authorization: Bearer $SOKUMITSU_API_KEY"
import os
import requests
BASE = "https://api.sokumitsu.com"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['SOKUMITSU_API_KEY']}"
res = session.get(f"{BASE}/api/v1/whoami", timeout=30)
res.raise_for_status()
print(res.json())
// whoami.mjs
const BASE = "https://api.sokumitsu.com";
const headers = { Authorization: `Bearer ${process.env.SOKUMITSU_API_KEY}` };
const res = await fetch(`${BASE}/api/v1/whoami`, { headers });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
console.log(await res.json());
応答の例です。
{
"organizationId": "org_k3v9x2m8q1w7z4t6y5r0pa",
"organizationName": "株式会社サンプル葬祭",
"apiKeyId": "ak_5f2c9e1a7b3d4c6e8f0a1b2c",
"scopes": ["data:write", "pii", "read"],
"authType": "api_key",
"userId": null,
"clientId": null,
"clientName": null
}
| 名前 | 型 | null になりうるか | 説明 |
|---|---|---|---|
organizationId | string | いいえ | 資格情報の組織。以降の呼び出しはすべてこの組織のデータが対象です |
organizationName | string | はい | 組織名 |
apiKeyId | string | いいえ | API キーの ID(ak_...)。OAuth のトークンでは oauth:<clientId> |
scopes | array<string> | いいえ | 持っている権限。アルファベット順です |
authType | string | いいえ | api_key(API キー)か oauth(OAuth のアクセストークン) |
userId | string | はい | OAuth のとき、同意した利用者の ID。API キーでは null |
clientId | string | はい | OAuth のとき、接続元のクライアント ID。API キーでは null |
clientName | string | はい | OAuth のとき、接続元が登録時に名乗った名前。API キーでは null |
キーが無効なら 401 が返ります。エラーの形は 共通仕様 を参照してください。
3. 見積を一覧する
GET /api/v1/quotes は見積を新しく更新された順に返します。既定は 1 ページ 20 件で、perPage は 1〜100 です。
curl -s "https://api.sokumitsu.com/api/v1/quotes?status=draft&perPage=5" \
-H "Authorization: Bearer $SOKUMITSU_API_KEY"
res = session.get(
f"{BASE}/api/v1/quotes",
params={"status": "draft", "perPage": 5},
timeout=30,
)
res.raise_for_status()
for q in res.json()["items"]:
print(q["id"], q["quoteNo"], q["totals"]["incTax"])
const url = new URL("/api/v1/quotes", BASE);
url.search = new URLSearchParams({ status: "draft", perPage: "5" });
const res = await fetch(url, { headers });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const { items, total } = await res.json();
console.log(total, items.map((q) => q.quoteNo));
{
"items": [
{
"id": "qot_m4p8w1z6k2r9t3y7v5x0bc",
"quoteNo": "Q-00000042",
"name": "家族葬プラン",
"type": "original",
"amendmentNumber": null,
"status": "draft",
"customerId": "cus_h7n2q9w4e1r8t5y3u6i0op",
"customerName": "山田 太郎",
"dealId": null,
"quoteDate": "2026-10-01",
"validUntil": "2026-10-31",
"staff": "佐藤",
"totals": { "exTax": 300000, "vat": 30000, "incTax": 330000 },
"updatedAt": "2026-10-01T03:15:42Z"
}
],
"total": 1,
"page": 1,
"perPage": 5
}
piiを持たないキーではcustomerNameがnullになります(個人情報)- 変更見積は既定で含めません。含めるには
includeAmendments=trueを付けます - 絞り込み・並び替えのパラメータは 見積 を参照してください
4. 見積を 1 件取得する
GET /api/v1/quotes/{quoteId} は、明細・合計・税率ごとの内訳・前受金・変更見積を含む詳細を返します。
curl -s https://api.sokumitsu.com/api/v1/quotes/qot_m4p8w1z6k2r9t3y7v5x0bc \
-H "Authorization: Bearer $SOKUMITSU_API_KEY"
quote_id = "qot_m4p8w1z6k2r9t3y7v5x0bc"
res = session.get(f"{BASE}/api/v1/quotes/{quote_id}", timeout=30)
if res.status_code == 404:
print("見積が見つかりません")
else:
res.raise_for_status()
quote = res.json()
print(quote["quoteNo"], quote["totals"], len(quote["lineItems"]))
const quoteId = "qot_m4p8w1z6k2r9t3y7v5x0bc";
const res = await fetch(`${BASE}/api/v1/quotes/${encodeURIComponent(quoteId)}`, { headers });
if (res.status === 404) console.log("見積が見つかりません");
else {
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const quote = await res.json();
console.log(quote.quoteNo, quote.totals, quote.lineItems.length);
}
応答のうち主な項目を抜粋します。全項目は 見積 を参照してください。
{
"id": "qot_m4p8w1z6k2r9t3y7v5x0bc",
"quoteNo": "Q-00000042",
"name": "家族葬プラン",
"type": "original",
"status": "draft",
"customerId": "cus_h7n2q9w4e1r8t5y3u6i0op",
"customerName": "山田 太郎",
"quoteDate": "2026-10-01",
"validUntil": "2026-10-31",
"totals": { "exTax": 300000, "vat": 30000, "incTax": 330000 },
"priceTypeId": "pty_c2v7b4n9m1q6w3e8r5t0yu",
"lineItems": [
{
"id": "qli_r6t1y8u3i9o2p5a7s4d0fg",
"productName": "家族葬 基本プラン",
"categoryName": "祭壇",
"unit": "式",
"quantity": 1,
"unitPrice": 300000,
"subtotal": 300000,
"taxType": "exclusive",
"taxRate": 10,
"taxName": "消費税 10%",
"lineType": "standard",
"options": []
}
],
"qualifiedInvoice": {
"taxBreakdown": [
{ "rate": 10, "taxClass": "standard_10", "label": "10%", "taxableBaseExTax": 300000, "taxAmount": 30000 }
],
"totalTaxableBaseExTax": 300000,
"totalTaxAmount": 30000
},
"advancePayments": [],
"advancePaymentTotal": 0,
"balanceDue": 330000,
"amendments": [],
"url": "https://app.sokumitsu.com/quotes/qot_m4p8w1z6k2r9t3y7v5x0bc",
"updatedAt": "2026-10-01T03:15:42Z"
}
他の組織の見積の ID を指定した場合も、存在しない ID と同じ 404 になります。
5. 顧客を登録する
POST /api/v1/customers で顧客を登録します。data:write と pii の両方が要ります。必須は displayName(宛名として使う表示名)だけです。
Idempotency-Key ヘッダーに要求ごとの一意な値(UUID など)を付けると、タイムアウトなどで同じ要求を再送しても顧客は 1 件しかできません(再送と冪等キー)。
curl -s -X POST https://api.sokumitsu.com/api/v1/customers \
-H "Authorization: Bearer $SOKUMITSU_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1d3c2e-8a4b-4f7e-9c1d-2b3a4e5f6a7b" \
-d '{
"customerType": "individual",
"lastName": "山田",
"firstName": "太郎",
"lastNameKana": "やまだ",
"firstNameKana": "たろう",
"displayName": "山田 太郎",
"phone": "03-0000-0000",
"email": "taro.yamada@example.com"
}'
import uuid
payload = {
"customerType": "individual",
"lastName": "山田",
"firstName": "太郎",
"lastNameKana": "やまだ",
"firstNameKana": "たろう",
"displayName": "山田 太郎",
"phone": "03-0000-0000",
"email": "taro.yamada@example.com",
}
# 再送するときは同じキーを使う。キーは要求ごとに 1 回だけ作る
idempotency_key = str(uuid.uuid4())
res = session.post(
f"{BASE}/api/v1/customers",
json=payload,
headers={"Idempotency-Key": idempotency_key},
timeout=30,
)
res.raise_for_status() # 新規は 201、同じキーの再送は 200
customer = res.json()
print(customer["id"], res.headers.get("Idempotent-Replayed"))
import { randomUUID } from "node:crypto";
const payload = {
customerType: "individual",
lastName: "山田",
firstName: "太郎",
lastNameKana: "やまだ",
firstNameKana: "たろう",
displayName: "山田 太郎",
phone: "03-0000-0000",
email: "taro.yamada@example.com",
};
// 再送するときは同じキーを使う。キーは要求ごとに 1 回だけ作る
const idempotencyKey = randomUUID();
const res = await fetch(`${BASE}/api/v1/customers`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json", "Idempotency-Key": idempotencyKey },
body: JSON.stringify(payload),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const customer = await res.json(); // 新規は 201、同じキーの再送は 200
console.log(customer.id, res.headers.get("Idempotent-Replayed"));
応答(201 Created)は登録した顧客の詳細です。
{
"id": "cus_h7n2q9w4e1r8t5y3u6i0op",
"displayName": "山田 太郎",
"customerType": "individual",
"companyName": null,
"phone": "03-0000-0000",
"email": "taro.yamada@example.com",
"prefecture": null,
"city": null,
"piiRedacted": false,
"updatedAt": "2026-10-01T03:20:11Z",
"lastName": "山田",
"firstName": "太郎",
"lastNameKana": "やまだ",
"firstNameKana": "たろう",
"department": null,
"jobTitle": null,
"salutation": "様",
"postalCode": null,
"street": null,
"building": null,
"note": null,
"customFields": {},
"externalSystem": null,
"externalId": null,
"createdAt": "2026-10-01T03:20:11Z",
"url": "https://app.sokumitsu.com/customers/cus_h7n2q9w4e1r8t5y3u6i0op",
"recentQuotes": []
}
- 本文に知らない項目があると
422になります。登録できる項目は 顧客 を参照してください - 外部システムの ID を
externalSystem・externalIdに入れておくと、連携元のレコードと対応づけられます
6. 見積の下書きを作る
POST /api/v1/quotes で見積を下書きとして作ります。data:write と pii の両方が要ります。必須は customerName(宛名)です。API で作れるのは下書きだけで、status に draft 以外を送ると 400 になります。
先に、明細に入れる商品の ID を GET /api/v1/products で調べます。
curl -s -G https://api.sokumitsu.com/api/v1/products \
--data-urlencode "search=家族葬" \
-H "Authorization: Bearer $SOKUMITSU_API_KEY"
{
"items": [
{
"id": "prd_w9e4r1t6y2u8i3o5p7a0sd",
"name": "家族葬 基本プラン",
"unit": "式",
"taxType": "exclusive",
"taxRate": 10,
"prices": [
{ "priceTypeId": "pty_c2v7b4n9m1q6w3e8r5t0yu", "priceTypeName": "一般", "price": 300000, "isActive": true }
]
}
],
"page": 1,
"perPage": 200,
"hasMore": false
}
(商品の応答は抜粋です。全項目は 商品 を参照してください。)
明細に productId だけを入れて unitPrice を省くと、見積の価格タイプ(priceTypeId。省くと組織の既定の価格タイプ)での商品価格が入ります。税額はサーバーが計算し直します。
curl -s -X POST https://api.sokumitsu.com/api/v1/quotes \
-H "Authorization: Bearer $SOKUMITSU_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 0b8e7d6c-5a4f-4e3d-8c2b-1a0f9e8d7c6b" \
-d '{
"name": "家族葬プラン",
"customerId": "cus_h7n2q9w4e1r8t5y3u6i0op",
"customerName": "山田 太郎",
"honorific": "様",
"quoteDate": "2026-10-01",
"items": [
{ "productId": "prd_w9e4r1t6y2u8i3o5p7a0sd", "qty": 1 }
]
}'
payload = {
"name": "家族葬プラン",
"customerId": customer["id"],
"customerName": customer["displayName"],
"honorific": "様",
"quoteDate": "2026-10-01",
"items": [{"productId": "prd_w9e4r1t6y2u8i3o5p7a0sd", "qty": 1}],
}
res = session.post(
f"{BASE}/api/v1/quotes",
json=payload,
headers={"Idempotency-Key": str(uuid.uuid4())},
timeout=60,
)
res.raise_for_status()
quote = res.json()
print(quote["quoteNo"], quote["status"], quote["totals"])
const res = await fetch(`${BASE}/api/v1/quotes`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json", "Idempotency-Key": randomUUID() },
body: JSON.stringify({
name: "家族葬プラン",
customerId: customer.id,
customerName: customer.displayName,
honorific: "様",
quoteDate: "2026-10-01",
items: [{ productId: "prd_w9e4r1t6y2u8i3o5p7a0sd", qty: 1 }],
}),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const quote = await res.json();
console.log(quote.quoteNo, quote.status, quote.totals);
応答(201 Created)は、4. 見積を 1 件取得する と同じ形の見積の詳細です。status は draft、url は画面でその見積を開く URL です。確定は画面で行ってください。
quoteDateを省くと、作成した日(日本時間)が入ります。expiryDateを省くとvalidUntilはnullです- API キーで作った見積は、担当者(
personInChargeId)が空になります。API キーは人に紐づかないためです - 明細・オプション・値引き行の指定方法は 見積 を参照してください
再送と冪等キー
作成の要求(POST /api/v1/customers・/deals・/quotes・/quotes/{id}/duplicate)は Idempotency-Key ヘッダーを受け付けます。
| 状況 | 応答 |
|---|---|
| 初めてのキー | 作成して 201 |
| 同じキー・同じ本文の再送(1 回目が完了済み) | 作成せずに 1 回目のレコードを 200 で返す。Idempotent-Replayed: true ヘッダーが付く |
| 同じキー・同じ本文の再送(1 回目が処理中) | 409。少し待って同じキーで再送する |
| 同じキーで別の本文・別のパス | 422 |
| 1 回目が失敗した(検証エラーなど) | キーは記録されないので、直して同じキーで送り直せる |
- キーは 1〜255 文字です。UUID を使ってください
- キーは資格情報ごとに別に扱います。別の API キーで同じキーを使っても、別の要求とみなします
- 詳しくは 共通仕様 を参照してください
うまくいかないとき
| ステータス | よくある原因 | 対処 |
|---|---|---|
401 | Authorization ヘッダーが無い、Bearer が付いていない、キーが失効・期限切れ、組織が削除予約中 | キーを確かめ、必要なら管理者に再発行してもらう |
402 | 組織の契約が有効でない | 管理者に契約状態を確かめてもらう |
403 | 権限(スコープ)が足りない。顧客・見積の登録で pii が無い | whoami の scopes を確かめ、必要な権限のキーを発行し直す(認証と権限) |
404 | ID の誤り、他の組織の ID | ID を一覧や検索で取り直す |
422 | 本文に知らない項目がある、必須項目が無い、形が違う | 本文やクエリの検証で弾いた場合は error.code が VALIDATION_ERROR で、error.extra.details に項目ごとの理由が入ります。見積の明細(items)の検証で弾いた場合は error.message に入ります |
429 | 回数制限を超えた | Retry-After ヘッダーの秒数だけ待って再試行する(共通仕様) |
問い合わせるときは、応答の X-Request-Id ヘッダー(本文の error.request_id と同じ値)を添えてください。