Kanorio

はじめに

クイックスタート

トークンの作成、最初のManagement API呼び出し、記事の公開、そしてContent Delivery APIからの読み取りまでを約10分で完了させましょう。

このクイックスタートでは、コードを使用してブログ記事を作成し、サイトの公開APIから読み取るまでの手順を説明します。

はじめる前に

  • Kanorioアカウントと、少なくとも1つのサイトが必要です。空のサイトでも問題ありません。
  • curl、またはSDKを使用する場合はNode.js 20以降が必要です。

1. パーソナルアクセストークンを作成する

パーソナルアクセストークンは knr_pat_ で始まり、選択したサイトと権限の範囲内でユーザーの代わりとして機能します。

  1. アカウント設定 › APIアクセス を開き、キーを作成を選択します。
  2. その他のツールを選択し、使用するサイトを選んで、コンテンツの編集権限プリセットを選択します。公開にはフルアクセスまたは公開権限が必要です。
  3. トークンをコピーします。トークンは一度しか表示されません。
export KANORIO_TOKEN="knr_pat_..."

トークンはサーバー上で管理してください。ブラウザのコードや公開リポジトリには絶対に含めないでください。その他のトークンタイプについては、認証を参照してください。

2. サイトを一覧表示する

すべてのManagement APIリクエストは、トークンをBearer認証情報として含め、https://app.kanorio.com/api/v1 に対して行います。

curl https://app.kanorio.com/api/v1/sites \
  -H "Authorization: Bearer $KANORIO_TOKEN"

リストは常に同じエンベロープ形式で返されます。サイトの id と publicUrl を確認してください。

{
  "data": [
    {
      "id": "ws_example123",
      "name": "Sourdough Studio",
      "role": "OWNER",
      "isPublished": true,
      "publicUrl": "https://sourdough.kanorio.com"
    }
  ],
  "hasMore": false,
  "nextCursor": null
}

3. 下書き記事を作成する

書き込み操作は下書きを作成します。公開するまで、ライブサイトに変更は反映されません。

curl -X POST https://app.kanorio.com/api/v1/sites/ws_example123/posts \
  -H "Authorization: Bearer $KANORIO_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "How we feed our sourdough starter",
    "excerpt": "The first thing we do every morning.",
    "contentMarkdown": "## Flour and water\n\nEqual weights, twice a day."
  }'

レスポンスは記事そのものであり、"status": "DRAFT" および post_example01 のような id が含まれます。

4. 記事を公開する

curl -X POST https://app.kanorio.com/api/v1/sites/ws_example123/posts/post_example01/publish \
  -H "Authorization: Bearer $KANORIO_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'

SITE_NOT_PUBLISHED エラーコードが返された場合は、POST /sites/{id}/publish を使用して一度サイトを公開してから、再度試してください。エラーの形式は常に一定であり、エラーで説明されています。

5. Content Delivery APIから読み取る

公開されたコンテンツは、トークンなしでサイトのアドレスから読み取ることができます。ステップ2で取得した publicUrl、または サイト設定 › 開発者 に表示されているシステム永続URLを使用してください。

curl "https://sourdough.kanorio.com/api/v1/collections/blog/items?limit=1&fields=title,excerpt"
{
  "data": [
    {
      "id": "post_example01",
      "slug": "how-we-feed-our-starter",
      "publishedAt": "2026-11-02T08:00:00.000Z",
      "fieldData": {
        "title": "How we feed our sourdough starter",
        "excerpt": "The first thing we do every morning."
      }
    }
  ],
  "hasMore": false,
  "nextCursor": null,
  "assets": {}
}

SDKを使用する

npm install @kanorio/sdk
import { createDeliveryClient, createManagementClient } from "@kanorio/sdk";

const management = createManagementClient({ token: process.env.KANORIO_TOKEN! });
const sites = await management.get("/sites");
const site = sites.data[0]!;

const post = await management.post("/sites/{id}/posts", {
  params: { id: site.id },
  body: { title: "How we feed our sourdough starter", contentMarkdown: "## Flour and water" },
});
await management.post("/sites/{id}/posts/{postId}/publish", { params: { id: site.id, postId: post.id }, body: {} });

const delivery = createDeliveryClient({ siteUrl: site.publicUrl! });
const latest = await delivery.get("/collections/{key}/items", { params: { key: "blog" }, query: { limit: 1 } });
console.log(latest.data[0]?.slug);

次のステップ