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

# Create

> Create a CometChat bot for an existing user with the REST API and relay its messages to your own webhook.

The `uid` must already belong to a [User](https://www.cometchat.com/docs/rest-api/users.md). If no such user exists, the API returns `ERR_UID_NOT_FOUND`.

`enabled` defaults to `false`, so send `enabled: true` — or call the [Update Bot API](https://www.cometchat.com/docs/rest-api/bots/update.md) afterwards — before the bot will relay anything. `groupChatSetting` defaults to `none`, so a new bot receives no group messages until you set it. `username` and `password` are stored only when `useBasicAuth` is `true`; otherwise they are discarded.

A bot's name and avatar belong to its user, not to the bot — set them with the [Update User API](https://www.cometchat.com/docs/rest-api/users/update.md).

## Constraints

| Item | Constraint | Notes |
| - | - | - |
| Bot UID | 50 characters | Must match an existing user. CometChat forces the UID to lowercase |
| Webhook URL | 255 characters | Must be a valid URL |
| Basic auth username | 50 characters | Ignored unless `useBasicAuth` is `true` |
| Basic auth password | 50 characters | Ignored unless `useBasicAuth` is `true` |

> [!WARNING]
>
> When `useBasicAuth` is `true`, the API returns the stored `password` value in the response. The example masks it as `********`; a real response contains the password you sent.

For the complete error reference, see [Error Guide](https://www.cometchat.com/docs/articles/error-guide.md).


## OpenAPI

````yaml post /bots
openapi: 3.0.0
info:
  title: Chat APIs
  description: Manage messages, users, groups for a particular app using our Chat API.
  version: '3.0'
servers:
  - url: https://{appId}.api-{region}.cometchat.io/v3
    variables:
      appId:
        default: appId
        description: (Required) App ID
      region:
        enum:
          - us
          - eu
          - in
        default: us
        description: Select Region
security: []
tags:
  - name: API Keys
    description: The API keys are used to authorise the APIs
  - name: Roles
    description: The roles are used to give user access rights
  - name: Users
    description: The REST collection for users.
  - name: Bots
    description: The bots relay messages from your app to a webhook.
  - name: Auth Tokens
    description: The auth tokens are used to login end users using client SDKs.
  - name: Blocked Users
    description: The REST collections for blocked users.
  - name: Friends
    description: List,add and remove friends by passing UID in path variables
  - name: Groups
    description: The REST collections for groups.
  - name: Banned Users
    description: Ban and Unban user by passing other UID in path variables.
  - name: Group Members
    description: The REST collections for group members.
  - name: Messages
    description: The REST collections for messages.
  - name: Conversations
    description: The REST collections for conversations.
  - name: Restrict Features
    description: Allows Restricting Features
  - name: Metrics
    description: Allows accessing Data Metrics
  - name: Triggers
    description: Allows adding triggers to a webhook.
  - name: Webhooks
    description: Allows accessing Webhooks.
  - name: Notifications
    description: Allows configuring Notifications core.
  - name: Moderation
    description: The REST collections for Moderations.
paths:
  /bots:
    post:
      tags:
        - Bots
      summary: Create
      description: Creates a new bot for an existing user
      operationId: create-bot
      requestBody:
        content:
          application/json:
            schema:
              required:
                - uid
                - webhookURL
              properties:
                uid:
                  description: >-
                    UID of an existing user to turn into a bot. Maximum 50
                    characters, forced to lowercase.
                  type: string
                  default: ''
                webhookURL:
                  description: >-
                    URL that receives the messages relayed to the bot. Maximum
                    255 characters.
                  type: string
                  default: ''
                groupChatSetting:
                  description: >-
                    Which group messages are relayed to the webhook. Possible
                    values: allMessages, slashedMessages, mentionedMessages,
                    none.
                  type: string
                  default: none
                  enum:
                    - allMessages
                    - slashedMessages
                    - mentionedMessages
                    - none
                useBasicAuth:
                  description: Sends HTTP basic auth credentials with every webhook call.
                  type: boolean
                  default: false
                username:
                  description: >-
                    Basic auth username. Maximum 50 characters. Ignored unless
                    useBasicAuth is true.
                  type: string
                  default: ''
                password:
                  description: >-
                    Basic auth password. Maximum 50 characters. Ignored unless
                    useBasicAuth is true.
                  type: string
                  default: ''
                enabled:
                  description: Whether the bot relays messages to its webhook.
                  type: boolean
                  default: false
              type: object
      responses:
        '200':
          description: Created a new Bot
          content:
            application/json:
              schema:
                properties:
                  data:
                    type: object
                type: object
              example:
                data:
                  uid: support-bot
                  webhookURL: https://example.com/webhooks/support-bot
                  groupChatSetting: mentionedMessages
                  useBasicAuth: true
                  username: support-bot
                  password: '********'
                  enabled: true
                  createdAt: 1763558400
      security:
        - apiKey: []
components:
  securitySchemes:
    apiKey:
      type: apiKey
      description: API Key with fullAccess scope(i.e. Rest API Key from the Dashboard).
      name: apikey
      in: header

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.