> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rheel.net/llms.txt
> Use this file to discover all available pages before exploring further.

# クイックスタート

> Rheel Chat APIを3ステップで始める

## 3ステップで始める

Rheel Chat APIを使用して、アプリケーションにリアルタイムチャット機能を統合しましょう。

### ステップ1: API Keyの取得

<Steps>
  <Step title="アカウント作成">
    [Rheel Chat](https://ecu.co.jp/rheel/chat-api)でアカウントを作成します。
  </Step>

  <Step title="アプリケーション作成">
    管理画面から新しいアプリケーションを作成します。
  </Step>

  <Step title="API Key取得">
    作成したアプリケーションのAPI Keyを取得します。このキーは管理操作（ユーザー作成など）に使用します。
  </Step>
</Steps>

<Warning>
  API Keyは秘密情報です。クライアントサイドのコードに含めないでください。
</Warning>

### ステップ2: ユーザーの作成とトークン発行

ユーザーをチャットシステムに登録し、セッショントークンを発行します。

<CodeGroup>
  ```bash cURL theme={null}
  # 1. ユーザーを作成
  curl -X POST https://<application_id>.chat.rheel.net/v1/users \
    -H "X-Rheel-API-Key: <API_KEY>" \
    -H "Content-Type: application/json" \
    -d '{
      "id": "user123",
      "name": "山田太郎",
      "avatar": "https://example.com/avatar.jpg"
    }'

  # 2. セッショントークンを発行
  curl -X POST https://<application_id>.chat.rheel.net/v1/users/user123/token \
    -H "X-Rheel-API-Key: <API_KEY>"
  ```

  ```javascript JavaScript theme={null}
  // 1. ユーザーを作成
  const createUser = async () => {
    const response = await fetch('https://<application_id>.chat.rheel.net/v1/users', {
      method: 'POST',
      headers: {
        'X-Rheel-API-Key': API_KEY,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        id: 'user123',
        name: '山田太郎',
        avatar: 'https://example.com/avatar.jpg'
      })
    });
    return response.json();
  };

  // 2. セッショントークンを発行
  const issueToken = async () => {
    const response = await fetch('https://<application_id>.chat.rheel.net/v1/users/user123/token', {
      method: 'POST',
      headers: {
        'X-Rheel-API-Key': API_KEY
      }
    });
    const data = await response.json();
    return data.token;
  };
  ```

  ```python Python theme={null}
  import requests

  # 1. ユーザーを作成
  def create_user():
      response = requests.post(
          'https://<application_id>.chat.rheel.net/v1/users',
          headers={
              'X-Rheel-API-Key': API_KEY,
              'Content-Type': 'application/json'
          },
          json={
              'id': 'user123',
              'name': '山田太郎',
              'avatar': 'https://example.com/avatar.jpg'
          }
      )
      return response.json()

  # 2. セッショントークンを発行
  def issue_token():
      response = requests.post(
          'https://<application_id>.chat.rheel.net/v1/users/user123/token',
          headers={'X-Rheel-API-Key': API_KEY}
      )
      data = response.json()
      return data['token']
  ```
</CodeGroup>

### ステップ3: チャンネルの作成とメッセージ送信

セッショントークンを使用して、チャンネルを作成しメッセージを送信します。

<CodeGroup>
  ```bash cURL theme={null}
  # 1. チャンネルを作成
  curl -X POST https://<application_id>.chat.rheel.net/v1/channels \
    -H "Authorization: Bearer <SESSION_TOKEN>" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "一般チャット",
      "user_ids": ["user123"]
    }'

  # 2. メッセージを送信
  curl -X POST https://<application_id>.chat.rheel.net/v1/channels/<channel_id>/messages \
    -H "Authorization: Bearer <SESSION_TOKEN>" \
    -H "Content-Type: application/json" \
    -d '{
      "text": "こんにちは！"
    }'
  ```

  ```javascript JavaScript theme={null}
  // 1. チャンネルを作成
  const createChannel = async (sessionToken) => {
    const response = await fetch('https://<application_id>.chat.rheel.net/v1/channels', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${sessionToken}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        name: '一般チャット',
        user_ids: ['user123']
      })
    });
    return response.json();
  };

  // 2. メッセージを送信
  const sendMessage = async (sessionToken, channelId) => {
    const response = await fetch(`https://<application_id>.chat.rheel.net/v1/channels/${channelId}/messages`, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${sessionToken}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        text: 'こんにちは！'
      })
    });
    return response.json();
  };
  ```

  ```python Python theme={null}
  # 1. チャンネルを作成
  def create_channel(session_token):
      response = requests.post(
          'https://<application_id>.chat.rheel.net/v1/channels',
          headers={
              'Authorization': f'Bearer {session_token}',
              'Content-Type': 'application/json'
          },
          json={
              'name': '一般チャット',
              'user_ids': ['user123']
          }
      )
      return response.json()

  # 2. メッセージを送信
  def send_message(session_token, channel_id):
      response = requests.post(
          f'https://<application_id>.chat.rheel.net/v1/channels/{channel_id}/messages',
          headers={
              'Authorization': f'Bearer {session_token}',
              'Content-Type': 'application/json'
          },
          json={'text': 'こんにちは！'}
      )
      return response.json()
  ```
</CodeGroup>

## 次のステップ

<CardGroup cols={2}>
  <Card title="API Overview" icon="book" href="/">
    APIの全体像と認証方式について理解する
  </Card>

  <Card title="WebSocket接続" icon="plug" href="/websocket">
    リアルタイム通信の実装方法を学ぶ
  </Card>

  <Card title="ユーザー管理" icon="users" href="/api-reference/endpoint/server-api/users/ユーザーの作成">
    ユーザー管理APIの詳細を確認する
  </Card>

  <Card title="メッセージング" icon="message" href="/api-reference/endpoint/server-api/messages/メッセージの投稿-メッセージの投稿（ファイル付き）">
    メッセージ機能の詳細を確認する
  </Card>
</CardGroup>

<Note>
  サポートが必要な場合は、[お問い合わせ](https://ecu.co.jp/rheel/chat-api/contact)からご連絡ください。
</Note>
