# Send WhatsApp Notifications

In this section, you'll learn how to send a new WhatsApp based notification using our programmable APIs.

### Sample Code

```
curl --location --request POST 'https://gateway.konverse.ai/ironman/api/v1/whatsApp/whatsappHSM' \
--header 'x-app-id: your app id' \
--header 'x-api-key: your app key' \
--header 'Content-Type: application/json' \
--data-raw '{
   "message": {
     "to": "919XXXXXXXXX",
     "templateName" : "message1",
     "language" : "<language-code>",
     "parameters": [
         "parameter1",
         "parameter2"
      ],
      "buttons" : []
   }
}'

```

### Step 1 - Authentication

Authentication of our WhatsApp API is done using the two request headers, **`<x-app-id>`** & **`<x-api-key>`.** Connect to our development team for your ID & Key.

### Step 2 - Using the API

Once your template is approved by WhatsApp & you've app ID & key, copy and paste the above cURL request with your credential and start testing.

## WhatsApp Notification Sending API

<mark style="color:green;">`POST`</mark> `https://gateway.konverse.ai/ironman/api/v1/whatsappHSM`

#### Headers

| Name         | Type   | Description             |
| ------------ | ------ | ----------------------- |
| x-app-id     | string | to be shared on request |
| x-api-key    | string | to be shared on request |
| Content-Type | string | application/json        |

#### Request Body

| Name         | Type   | Description                                                                                                                                                                                                                                             |
| ------------ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| to           | string | Mobile number to which WhatsApp notification has to be sent, prefixed with country code without + sign for e.g. "919876543210".                                                                                                                         |
| templateName | string | Name of the template pre-approved by WhatsApp.                                                                                                                                                                                                          |
| parameter    | string | An array of parameters that will replace the placeholder’s in the approved template. The number of parameters in a message template and the length of the array must be equal. Send an empty array if the template doesn't have any parameters e.g. \[] |
| file         | string | This is an object type. Use only if the template has an attachment.                                                                                                                                                                                     |
| file.type    | string | document / video / image                                                                                                                                                                                                                                |
| file.url     | string | Public URL of the attachment                                                                                                                                                                                                                            |
| file.name    | string | Optional caption for the attachment                                                                                                                                                                                                                     |
| buttons      | string | Applicable only if the template has buttons. Send an empty array for Call to Action buttons, e.g. \[].                                                                                                                                                  |
| buttons.type | string | Only if the button in the template is of type URL then type = “url”                                                                                                                                                                                     |
| buttons.url  | string | URL suffix to the pre-approved URL with the template. WhatsApp does not allow completely dynamic URL. A part of URL is pre-approved with the template, and only URL suffix is sent in the API.                                                          |
| language     | String | Language Code (optional). Refer WhatsApp documentation for supported language - [Supported Language](https://developers.facebook.com/docs/whatsapp/api/messages/message-templates#supported-languages)                                                  |

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

```
{
    "status": "success",
    "message": "message sent successfully",
    "messageId": "gBEGkXdgloBAAgluX2iGtsi"
}
```

{% endtab %}

{% tab title="400 The number of parameters sent is not matching with the approved number of parameters in the template." %}

```
{
    "status": "failed",
    "error": {
        "meta": {
            "api_status": "stable",
            "version": "2.27.12"
        },
        "errors": [
            {
                "code": 2000,
                "title": "Number of parameters does not match the expected number of params",
                "details": "number of localizable_params (1) does not match the expected number of params (2)",
                "href": "https://developers.facebook.com/docs/whatsapp/faq#faq_1612022582274564"
            }
        ]
    }
}
```

{% endtab %}

{% tab title="401 Please check your x-app-id & your x-api-key " %}

```
{
    "status": "failed",
    "messaged": "Unauthorized"
}
```

{% endtab %}
{% endtabs %}

### Template with dynamic CTA URL buttons & File

```
curl --location --request POST 'https://gateway.konverse.ai/ironman/api/v1/whatsApp/whatsappHSM' \
--header 'x-app-id: your app id' \
--header 'x-api-key: your app key' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message": {
        "to": "1XXXXXXXX",
        "templateName": "<templatename>",
        "parameters": [
            <parameters>
        ],
        "file": {
            "type": "<document|image|video|audio>",
            "url": "<url - must end with .pdf/.doc/.png/.jpg>"
        },
        "buttons": [
            {
                "type": "url",
                "text": "<url parameter>"
            }
        ]
    }
}'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.konverse.ai/messaging-channels/whatsapp/whatsapp-template.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
