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

# Add Reaction

> Add a reaction to a message. <br/> *Added in v2.58.0*

#### Recipes

<AccordionGroup>
  <Accordion title="Add a reaction to message">
    <Steps>
      <Step title="1. Set the message ID">
        Provide the `message_id` of the message you want to react to.

        ```curl {7} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 2e80acd7f3d9c1e79312e0d1dafd6691ba012bba" \
        -d '{
          "name": "like"
        }' \
        https://api.quickblox.com/chat/Message/5d75327ba28f9a0f32cb0f99/reactions
        ```
      </Step>

      <Step title="2. Set the reaction type">
        Provide a valid `name` of the reaction, such as `"like"`, `"love"`, or `"haha"`.

        ```curl {5} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 2e80acd7f3d9c1e79312e0d1dafd6691ba012bba" \
        -d '{
          "name": "like"
        }' \
        https://api.quickblox.com/chat/Message/5d75327ba28f9a0f32cb0f99/reactions
        ```
      </Step>

      <Step title="3. As a result, the API returns a '200 OK' status code, indicating that the reaction was added.">
        ```curl theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 2e80acd7f3d9c1e79312e0d1dafd6691ba012bba" \
        -d '{
          "name": "like"
        }' \
        https://api.quickblox.com/chat/Message/5d75327ba28f9a0f32cb0f99/reactions
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Add a reaction to message with API key">
    <Steps>
      <Step title="1. Use 'Authorization' header to pass API key">
        ```curl {2} theme={null}
        curl -X GET \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -H "On-Behalf-Of: 123" \
        -d '{
          "name": "like"
        }' \
        https://api.quickblox.com/chat/Message/5d75327ba28f9a0f32cb0f99/reactions
        ```
      </Step>

      <Step title="2. Use 'On-Behalf-Of' header to pass user id">
        ```curl {3} theme={null}
        curl -X GET \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -H "On-Behalf-Of: 123" \
        -d '{
          "name": "like"
        }' \
        https://api.quickblox.com/chat/Message/5d75327ba28f9a0f32cb0f99/reactions
        ```
      </Step>

      <Step title="3. Set the message ID">
        Provide the `message_id` of the message you want to react to.

        ```curl {7} theme={null}
        curl -X POST \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -H "On-Behalf-Of: 123" \
        -d '{
          "name": "like"
        }' \
        https://api.quickblox.com/chat/Message/5d75327ba28f9a0f32cb0f99/reactions
        ```
      </Step>

      <Step title="4. Set the reaction type">
        Provide a valid `name` of the reaction, such as `"like"`, `"love"`, or `"haha"`.

        ```curl {5} theme={null}
        curl -X POST \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -H "On-Behalf-Of: 123" \
        -d '{
          "name": "like"
        }' \
        https://api.quickblox.com/chat/Message/5d75327ba28f9a0f32cb0f99/reactions
        ```
      </Step>

      <Step title="5. As a result, the API returns a '200 OK' status code, indicating that the reaction was added.">
        ```curl theme={null}
        curl -X POST \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -H "On-Behalf-Of: 123" \
        -d '{
          "name": "like"
        }' \
        https://api.quickblox.com/chat/Message/5d75327ba28f9a0f32cb0f99/reactions
        ```
      </Step>
    </Steps>
  </Accordion>
</AccordionGroup>

**Duplicate Reactions**

If the user has already added the same reaction to the message, the request will be silently ignored and treated as successful.
No duplicate reactions will be created.

**Reaction Limits**

* **Per User Per Message:** A user can add up to **20 different reactions** to a single message.
* **Per Message (All Users):** A message can have up to **20 distinct reaction types** total.

**Public Dialog Restriction**

Reactions are not supported for messages in `type=1` (PUBLIC) dialog.
If you attempt to add a reaction to a message in a `type=1` (PUBLIC) dialog, the request will fail with an error.

#### Path Parameters

<ParamField path="chat_message_id" type="string" required> ID of the message. Generated automatically by the server after message creation. </ParamField>

#### Body Parameters

<ParamField body="name" type="string" required>
  The type of reaction to add.
  Examples: `"like"`, `"love"`, `"haha"`, `"angry"`.
</ParamField>

#### Headers

<ParamField header="QB-Token" type="string" required> A user session token. See [Authentication](/reference/authentication) page to learn more about session tokens. Must be used either QB-Token or Authorization. </ParamField>
<ParamField header="Authorization" type="string" default="ApiKey {your_api_key}"> API key from Dashboard. Expected format: `ApiKey {your_api_key}`. Must be used either QB-Token or Authorization.</ParamField>
<ParamField header="On-Behalf-Of" type="string">User ID. The user ID of the user on whose behalf the request is being made.</ParamField>

#### Responses

<AccordionGroup>
  <Accordion title="200">
    Reaction successfully added
  </Accordion>

  <Accordion title="400">
    An error response

    <ResponseField name="errors" type="array of strings" />
  </Accordion>

  <Accordion title="403">
    An error response

    <ResponseField name="errors" type="array of strings" />
  </Accordion>

  <Accordion title="404">
    An error response

    <ResponseField name="errors" type="array of strings" />
  </Accordion>

  <Accordion title="422">
    An error response

    <ResponseField name="errors" type="array of strings" />
  </Accordion>
</AccordionGroup>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST \
  -H "Content-Type: application/json" \
  -H "QB-Token: eddf864695d72d33b959eec2ae6c640d817dfada" \
  -d '{
    "name":"like"
  }' \
  https://api.quickblox.com/chat/Message/5d75327ba28f9a0f32cb0f99/reactions
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  Empty body
  ```

  ```json 400 theme={null}
  // Maximum reaction types for this message reached (20).
  {
    "errors": [
      "This message has reached the maximum number of allowed reaction types (20). No additional reaction types can be added."
    ]
  }
  // Maximum reactions per message reached (20).
  {
    "errors": [
      "You have reached the maximum number of reactions (20) allowed per message."
    ]
  }

  // Missing or invalid "name" parameter.
  {
    "errors": [
      "Invalid or missing \"name\" parameter."
    ]
  }

  // Missing or invalid "message_id" parameter.
  {
    "errors": [
      "Invalid or missing \"message_id\" parameter."
    ]
  }
  ```

  ```json 403 theme={null}
  {
    "errors": [
      "You don't have appropriate permissions to perform this operation"
    ]
  }
  ```

  ```json 404 theme={null}
  {
    "errors": [
      "Message not found for the specified user and message ID."
    ]
  }
  ```

  ```json 422 theme={null}
  {
    "errors": [
      "Reactions are not allowed in public dialogs."
    ]
  }
  ```
</ResponseExample>
