> For the complete documentation index, see [llms.txt](https://docs.lipachat.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lipachat.com/api/sending-buttons.md).

# Sending Buttons

🔒 WhatsApp 24-Hour Session Rule

> Before sending buttons, make sure the WhatsApp session with the user is **active**.
>
> **If the user has not messaged your business within the last 24 hours, WhatsApp requires the first message to be a&#x20;*****template message***.
>
> After the customer replies, the 24-hour session opens and you may send button messages using this API.\
> **For sandbox testing**, send your join code to the sandbox number to activate your session.\
> [Learn more](https://app.gitbook.com/o/rJyj7TfON4zeW56KoQjM/s/2JHt6V4YwZLX6ZUdLqMy/~/changes/87/guides/joincodes)

WhatsApp offers an API to send quick reply buttons to users. You can send up to a maximum of three buttons. To send more, consider using [Sending Interactive Lists](/api/sending-interactive-lists.md)

<div align="center" data-full-width="true"><figure><img src="/files/tPFTmJs1hetBhwkQ90RY" alt="" width="375"><figcaption></figcaption></figure></div>

<mark style="color:green;">`POST`</mark> <https://gateway.lipachat.com/api/v1/whatsapp/interactive/buttons>

**Headers**

| Name         | Value                                                                          |
| ------------ | ------------------------------------------------------------------------------ |
| Content-Type | `application/json`                                                             |
| apiKey       | Get apiKey from App portal settings tab<https://app.lipachat.com/app/settings> |

**Body**

| Name              | Type   | Description                                                                                                        |
| ----------------- | ------ | ------------------------------------------------------------------------------------------------------------------ |
| messageId         | string | A unique identifier for the message. This will be used to track the message status and for deduplication purposes. |
| message           | string | The message being sent.                                                                                            |
| from              | string | Sandbox number +254110090747 or your own WABA phone number.                                                        |
| to                | string | Receiver phone number. It should start with a country code.                                                        |
| buttons\[0].id    | string | Unique identifier of button in your app. eg 1 or YES\_BTN                                                          |
| buttons\[0].title | string | Text to be shown on button                                                                                         |

{% hint style="info" %}
"*buttons*" field is a list or array that accepts a minimum of 1 items and  a maximum of 3 items.
{% endhint %}

{% tabs %}
{% tab title="Curl" %}

```sh
curl --location 'https://gateway.lipachat.com/api/v1/whatsapp/interactive/buttons' \
--header 'apiKey: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "text": "Hello John Doe, are you interested to learn more about our products?",
  "buttons": [
    {
      "id": "1",
      "title": "YES"
    },
    {
      "id": "2",
      "title": "NO"
    },
    {
      "id": "3",
      "title": "Maybe"
    }
  ],
  "messageId": "875d25c2-0cb1-4270-a536-7b6dc16568b5",
  "to": "254XXXXX",
  "from": "254110090747"
}'
```

{% endtab %}

{% tab title="Java" %}

```java
// Create an instance of OkHttpClient
OkHttpClient client = new OkHttpClient().newBuilder()
    .build();

// Define the media type for the request
MediaType mediaType = MediaType.parse("application/json");

// Create the request body with the necessary JSON payload using a text block
RequestBody body = RequestBody.create(mediaType, """
{
  "text": "Hello John Doe, are you interested to learn more about our products?",
  "buttons": [
    {
      "id": "1",
      "title": "YES"
    },
    {
      "id": "2",
      "title": "NO"
    },
    {
      "id": "3",
      "title": "Maybe"
    }
  ],
  "messageId": "9f1a77f0-2240-4027-af00-c8d90469068b",
  "to": "254XXXXX",
  "from": "254110090747"
}
""");

// Build the request with the required headers
Request request = new Request.Builder()
    .url("https://gateway.lipachat.com/api/v1/whatsapp/interactive/buttons")
    .method("POST", body)
    .addHeader("apiKey", "YOUR_API_KEY")
    .addHeader("Content-Type", "application/json")
    .build();

// Execute the request and get the response
Response response = client.newCall(request).execute();


```

{% endtab %}

{% tab title="Javascript" %}

```ruby
const axios = require('axios');
let data = JSON.stringify({
  "text": "Hello John Doe, are you interested to learn more about our products?",
  "buttons": [
    {
      "id": "1",
      "title": "YES"
    },
    {
      "id": "2",
      "title": "NO"
    },
    {
      "id": "3",
      "title": "Maybe"
    }
  ],
  "messageId": "a1950882-b248-4f40-be1c-231bf64b024d",
  "to": "254XXXXX",
  "from": "254110090747"
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://gateway.lipachat.com/api/v1/whatsapp/interactive/buttons',
  headers: { 
    'apiKey': 'YOUR_API_KEY', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});


```

{% endtab %}
{% endtabs %}

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
      "timestamp": "2023-08-06T01:27:56.825898971",
      "data": {
            "messageId": "7addc006-07db-4fae-aac5-b285903b41d4",
            "waId": "wamid.HBgMMjU0NzE3NzQ2NTY1FQIAEnRgSRjJGRkMzNkQ0QUVENTIxQ0NBAA==",
            "status": "SENT",
            "statusDesc": "Message sent successfully"
      },
      "status": "success",
      "message": "",
      "errors": null
}
```

{% endtab %}

{% tab title="400" %}

```json
{
      "timestamp": "2023-08-06T17:50:35.701+00:00",
      "status": 400,
      "error": "Bad Request",
      "path": "/api/v1/whatsapp/message/text"
}
```

{% endtab %}

{% tab title="401" %}

```json
{
      "timestamp": "2023-08-06T20:49:48.455464058",
      "data": null,
      "status": "success",
      "message": "Invalid credentials",
      "errors": null
}
```

{% endtab %}
{% endtabs %}
