> ## 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.

# ユーザーの作成

> 新規ユーザーを作成します。



## OpenAPI

````yaml post /users
openapi: 3.0.0
info:
  title: Rheel Chat API
  version: 1.0.1
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
  description: >-
    RheelのChat API仕様です。主に以下の2種類のエンドポイントを提供し、 認証方式によって利用方法が異なります。

    1. **Server Request**

    管理者（あるいはバックエンドサーバー）が、管理画面で発行したアプリケーション独自のAPI Key を用いた、ユーザー管理 (ユーザー作成・削除など)
    やセッショントークンの発行などを行う際のエンドポイントです。


    2. **User Request**

    セッショントークン発行のエンドポイントを介して取得したセッショントークンを用いた、メッセージの投稿やチャンネルの閲覧・参加などのエンドポイントです。


    ![ユーザーリクエストとサーバーリクエストの概念図](./images/request-image.png)


    ---

    ## 認証の流れ

    1. 管理画面からアプリケーション独自の API Key を取得します。

    これはサーバーサイド(管理系)の認証に使用します。


    2. エンドユーザーがログインすると、上記の API Key を用いてユーザーごとに

    セッショントークンを発行します。


    3. ユーザーは、フロントエンド (Web クライアントやモバイルアプリなど) から

    セッショントークンを利用してチャットサービスにアクセスし、メッセージの送受信や

    チャンネルの閲覧・参加を行います。



    Webhookのイベントやユーザーの作成・削除、権限管理などについて、詳しくはヘルプページをご覧ください。
servers:
  - url: https://<application_id>.chat.rheel.net/v1
    description: 本番サーバー
    variables:
      application_id:
        default: YOUR_APP_ID（RheelチャットインスタンスのアプリケーションID）
security: []
tags:
  - name: Users
  - name: Channels
  - name: Messages
  - name: Bots
paths:
  /users:
    post:
      tags:
        - Users
      summary: ユーザーの作成
      description: 新規ユーザーを作成します。
      operationId: Users_createUser
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Users.CreateUserRequest'
      responses:
        '200':
          description: ユーザーの作成完了
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Users.User'
        '400':
          description: 入力内容が不正です
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error.BadRequestError'
        '401':
          description: 認証に失敗しました
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error.UnauthorizedError'
        '403':
          description: アクセス権がありません
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error.ForbiddenError'
        '404':
          description: リソースが存在しません
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error.NotFoundError'
        '500':
          description: サーバーでエラーが発生しました。時間をおいて再度お試しください。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error.InternalServerError'
      security:
        - ServerApiKeyAuth: []
components:
  schemas:
    Users.CreateUserRequest:
      type: object
      required:
        - display_name
        - role
      properties:
        id:
          allOf:
            - $ref: '#/components/schemas/UserId'
          description: ユーザーの一意な識別子（指定しない場合は自動生成されます）
        display_name:
          type: string
          minLength: 1
          maxLength: 200
          description: ユーザーの表示名
        icon_url:
          type: string
          nullable: true
          description: ユーザーアイコンのURL
        role:
          allOf:
            - $ref: '#/components/schemas/Users.UserRole'
          description: ユーザーの権限・役割(Admin:管理者, Member:一般ユーザー)
        metadata:
          type: object
          additionalProperties: {}
          nullable: true
          description: 任意の追加メタデータ
    Users.User:
      type: object
      required:
        - id
        - display_name
        - role
      properties:
        id:
          allOf:
            - $ref: '#/components/schemas/UserId'
          description: ユーザーの一意な識別子（ユーザー作成時に任意のidを指定できます）
        display_name:
          type: string
          minLength: 1
          maxLength: 200
          description: ユーザーの表示名
        icon_url:
          type: string
          nullable: true
          description: ユーザーアイコンのURL
        role:
          allOf:
            - $ref: '#/components/schemas/Users.UserRole'
          description: ユーザーの権限・役割(Admin:管理者, Member:一般ユーザー)
        created_at:
          type: string
          format: date-time
          description: 作成日時
          readOnly: true
        updated_at:
          type: string
          format: date-time
          nullable: true
          description: 更新日時
          readOnly: true
        deleted_at:
          type: string
          format: date-time
          nullable: true
          description: 削除日時
          readOnly: true
        metadata:
          type: object
          additionalProperties: {}
          nullable: true
          description: 任意の追加メタデータ
    Error.BadRequestError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              enum:
                - BAD_REQUEST
            errors:
              type: array
              items:
                $ref: '#/components/schemas/Error.ValidationError'
          required:
            - message
            - code
      allOf:
        - $ref: '#/components/schemas/TypeSpec.Http.BadRequestResponse'
      description: 入力内容が不正です
    Error.UnauthorizedError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              enum:
                - UNAUTHORIZED
          required:
            - message
            - code
      allOf:
        - $ref: '#/components/schemas/TypeSpec.Http.UnauthorizedResponse'
      description: 認証に失敗しました
    Error.ForbiddenError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              enum:
                - FORBIDDEN
          required:
            - message
            - code
      allOf:
        - $ref: '#/components/schemas/TypeSpec.Http.ForbiddenResponse'
      description: アクセス権がありません
    Error.NotFoundError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              enum:
                - NOT_FOUND
          required:
            - message
            - code
      allOf:
        - $ref: '#/components/schemas/TypeSpec.Http.NotFoundResponse'
      description: リソースが存在しません
    Error.InternalServerError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            code:
              type: string
              enum:
                - INTERNAL_SERVER_ERROR
          required:
            - message
            - code
      allOf:
        - type: object
          description: ''
      description: サーバーでエラーが発生しました。時間をおいて再度お試しください。
    UserId:
      type: string
      minLength: 1
      maxLength: 100
      pattern: ^[a-zA-Z0-9_-]+$
    Users.UserRole:
      type: string
      enum:
        - Admin
        - Member
    Error.ValidationError:
      type: object
      required:
        - field
        - message
        - code
      properties:
        field:
          type: string
        message:
          type: string
        code:
          type: string
      description: バリデーションエラー詳細
    TypeSpec.Http.BadRequestResponse:
      type: object
      description: The server could not understand the request due to invalid syntax.
    TypeSpec.Http.UnauthorizedResponse:
      type: object
      description: Access is unauthorized.
    TypeSpec.Http.ForbiddenResponse:
      type: object
      description: Access is forbidden.
    TypeSpec.Http.NotFoundResponse:
      type: object
      description: The server cannot find the requested resource.
  securitySchemes:
    ServerApiKeyAuth:
      type: apiKey
      in: header
      name: X-Rheel-API-Key
      description: 管理系API呼び出し用のAPIキーを指定します

````