# Messaging

## Introduction

Message API calls are sent to the `/v1/messages` endpoint regardless of message type, but the content of the JSON message body differs for each type of message type (text, image, etc.). See the following documentation for information regarding the type of messages you want to send.

* [Text Messages](https://developers.facebook.com/docs/whatsapp/api/messages/text)
* [Templates Messages](https://developers.facebook.com/docs/whatsapp/api/messages/message-templates)
* [Interactive Messages](https://developers.facebook.com/docs/whatsapp/guides/interactive-messages)
* [Media Messages](https://developers.facebook.com/docs/whatsapp/api/messages/media)
* [Other Message Types](https://developers.facebook.com/docs/whatsapp/api/messages/contacts-location-messages)

## Send Message

<mark style="color:green;">`POST`</mark> `https://api.whatso.net/v1/messages`

To send a message, use the request URL and the following body parameters.

#### Request Body

| Name                                                 | Type   | Description                                                                                                       |
| ---------------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------- |
| username<mark style="color:red;">\*</mark>           | string | Enter username of your account which you will find in WhatsoNxt panel.                                            |
| password<mark style="color:red;">\*</mark>           | string | Enter password of your account which you will find in WhatsoNxt panel.                                            |
| from<mark style="color:red;">\*</mark>               | string | WhatsApp Business Number with Country Code.                                                                       |
| to<mark style="color:red;">\*</mark>                 | string | Recipients Mobile number with Country Code.                                                                       |
| type<mark style="color:red;">\*</mark>               | string | For approved template message send "template".                                                                    |
| template:language<mark style="color:red;">\*</mark>  | string | Pass language of your approved template.                                                                          |
| name<mark style="color:red;">\*</mark>               | string | Pass template name which you entered at time of template creation.                                                |
| apicomponents:type<mark style="color:red;">\*</mark> | string | Pass body for text variables, header for image, footer for button.                                                |
| parameters:type<mark style="color:red;">\*</mark>    | string | <p>Pass text for text variable in body.</p><p>If header has image then pass image.</p><p>Pass text in footer.</p> |
| sub\_type                                            | string | If approved template has button in footer then pass url.                                                          |
| index                                                | string | If approved template has button in footer then pass "0".                                                          |
| parameters:value<mark style="color:red;">\*</mark>   | string | Pass variable value in body, image link in header, website url in footer.                                         |

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

```javascript
{
  "responsecode": 200,
  "api_status": "stable",
  "response": "success",
  "message": "success",
  "messageid": "147895"
}
```

{% endtab %}
{% endtabs %}

#### &#x20;Example 1 - Sending Text Template Message

```
{
  "username": "AAA1111AAA678AAA9xxxxxxxxxxxxx",
  "password": "AAA2345AAA678AAA9xxxxxxxxxxxxx",
  "from": "918866xxxx",
  "to": "918866xxxx",
  "type": "template",
  "template": {
    "language": {
      "code": "en"
    },
    "name": "template_name",
    "apicomponents": [ ]
  }
}
```

#### Example 2 - Sending Text Template Message With Parameters

```
{
  "username": "AAA1111AAA678AAA9xxxxxxxxxxxxx",
  "password": "AAA2345AAA678AAA9xxxxxxxxxxxxx",
  "from": "918866xxxx",
  "to": "918866xxxx",
  "type": "template",
  "template": {
    "language": {
      "code": "en"
    },
    "name": "template_name",
    "apicomponents": [
    {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "value": "hello"
          },
           {
            "type": "text",
            "value": "123454"
          }
        }
     ]
  }
}
```

#### Example 3 - Sending Media Template Message With Parameters

```
{
  "username": "AAA1111AAA678AAA9xxxxxxxxxxxxx",
  "password": "AAA2345AAA678AAA9xxxxxxxxxxxxx",
  "from": "918866xxxx",
  "to": "918866xxxx",
  "type": "template",
  "template": {
    "language": {
      "code": "en"
    },
    "name": "template_name",
    "apicomponents": [
      {
        "type": "header",
        "parameters": [
          {
            "type": "image",
            "value": "https://link-to-your-image.jpg"
          }
        ]
      },
       {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "value": "thanks"
          }
        ]
      },
       {
        "type": "button",
        "parameters": [
          {
            "type": "text",
            "value": "https://your-domain-name.com"
          }
        ],
        "sub_type": "url",
        "index": "0"
      }
    ]
  }
}
```
