> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.wanotifier.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Messaging API - Send Messages During Active Conversation Window

If you want to send free-form WhatsApp messages from your  website, app, or automation tools like Zapier or Pabbly, you can use our Messages API to do so. Kindly note that you'll be able to send messages using this API only during an **active conversation window**.

||| View our full REST API [Postman collection here](https://www.postman.com/wanotifier/wanotifier/collection/xfjfce8/wanotifier-api)

**Note:** This is an advanced feature and may require a developer to implement if you’re not familiar with REST API.

### Table of Contents

* [Messaging API Overview](#3-messaging-api-overview)
* [Message Types & Payloads](#3-message-types-payloads)
* [Message Status & Responses](#3-message-status-responses)
---

### Messaging API Overview

Send a WhatsApp message to a contact using their WhatsApp number or contact ID.

###### Request syntax

```
POST https://app.wanotifier.com/api/v1/messages?key=<YOUR_API_KEY>
```

###### Request POST data

```json
{
    "recipient": {
        "whatsapp_number": "+919876543210",   // WhatsApp number (with country code)
        "contact_id": 123456                  // (optional) Contact ID
    },
    "message": {
        "type": "<TYPE>",                     // Message type (see below)
        "<type_payload>": { ... }             // Message body specific to type (see below)
    }
}
```

*You must specify at least one recipient field: either&#32;`whatsapp_number`&#32;or&#32;`contact_id`. If both are provided,&#32;`contact_id`&#32;takes priority.*

###### Request fields

| Field name | Type | Description |
| ---- |
| key | string | Your WANotifier API key. You can get it from the [Automations > Integrations > API Integration](https://app.wanotifier.com/integrations/api/) page from the **API Keys** tab. **Required**. |
| recipient | object | Recipient information: WhatsApp number or contact ID. |
| message | object | Message object (type + type-specific payload, details below). |

###### Example request

```
curl --location 'https://app.wanotifier.com/api/v1/messages?key=A7X4P9Q2MZ1D6T8R' \
--header 'Content-Type: application/json' \
--data '{
    "recipient": {
        "whatsapp_number": "+919876543210"
    },
    "message": {
        "type": "text",
        "text": {
            "body": "Hello, this is a test message from API."
        }
    }
}'
```

---

### Message Types & Payloads

The `type` field in the `message` object determines what kind of WhatsApp message you send. We have tried to keep the structure of these requests as similar to the [WhatsApp Cloud API Messaging API](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages) as possible.

Payload structure for each message type:

1. [Text message](#6-1-text-message)
2. [Image message](#6-2-image-message)
3. [Video message](#6-3-video-message)
4. [Document message](#6-4-document-message)
5. [Audio message](#6-5-audio-message)
6. [Sticker message](#6-6-sticker-message)
7. [Location message](#6-7-location-message)
8. [Interactive Flow message](#6-8-interactive-flow-message)
9. [Interactive list message](#6-8-interactive-list-message)
10. [Interactive button message](#6-8-interactive-button-message)

###### 1. Text message

```json
{
    "type": "text",
    "text": {
        "preview_url": true,			// Show link preview
        "body": "Your message goes here"	// Text message content
    }
}
```

###### 2. Image message

```json
{
    "type": "image",
    "image": {
        "link": "https://example.com/path/image.jpg",	// Static image file URL
        "caption": "Optional caption"			// Image caption
    }
}
```

* Only static image URLs hosted on public servers are supported. Google drive or other dynamic page links not allowed.
* Supported file types: jpeg and png
* Max file size: 5 MB

###### 3. Video message

```json
{
    "type": "video",
    "video": {
        "link": "https://yourdomain.com/path/video.mp4",	// Static video file URL
        "caption": "Optional caption"			// Video caption
    }
}
```

* Only static video URLs hosted on public servers are supported. Google drive or other dynamic page links not allowed.
* Supported file types: mp4 and 3gp
* Max file size: 15 MB

###### 4. Document message

```json
{
    "type": "document",
    "document": {
        "link": "https://yourdomain.com/path/file.pdf",	// Static document file URL
        "filename": "OptionalFileName.pdf",		// Document final name
        "caption": "Optional caption"			// Document caption
    }
}
```

* Only static document URLs hosted on public servers are supported. Google drive or other dynamic page links not allowed.
* Support file formats: txt, xls, xlsx, doc, docx, ppt, pptx and pdf
* Max file size: 100 MB

###### 5. Audio message

```json
{
    "type": "audio",
    "audio": {
        "link": "https://yourdomain.com/path/audio.mp3"	// Static audio file URL
    }
}
```

* Only static audio URLs hosted on public servers are supported. Google drive or other dynamic page links not allowed.
* Support file formats: aac, amr, mp3, m4a and ogg
* Max file size: 16 MB

###### 6. Sticker message

```json
{
    "type": "sticker",
    "sticker": {
        "link": "https://yourdomain.com/path/sticker.webp"	// Static sticker file URL
    }
}
```

* Only static sticker URLs hosted on public servers are supported. Google drive or other dynamic page links not allowed.
* Support file formats: webp (animated or static)
* Max file size: 500 KB for animated webp and 100 KB for static webp

###### 7. Location message

```json
{
    "type": "location",
    "location": {
        "latitude": 18.5204,		// Location latitude
        "longitude": 73.8567,		// Location longitude
        "name": "Company HQ",		// Location name
        "address": "Baner, Pune, India"	// Location address
    }
}
```

###### 8. Interactive Flow message

```json
{
  "type": "interactive",
  "interactive": {
    "type": "flow",
    "header": {
      "type": "text",			// Flow header type
      "text": "Flow message header"	// Flow header text
    },
    "body": {
      "text": "Flow message body"	// Flow body text
    },
    "footer": {
      "text": "Flow message footer"	// Flow footer text
    },
    "action": {
      "name": "flow",
      "parameters": {
        "flow_message_version": "3",	// Flow version
        "flow_id": "sample_flow_id",	// Flow unique id
        "flow_cta": "Book!"		// Flow call-to-action button text
      }
    }
  }
}
```

###### 9. Interactive list message

```json
{
  "type": "interactive",
  "interactive": {
    "type": "list",
    "header": {
      "type": "text",			// List header type
      "text": "Flow message header"	// List header text
    },
    "body": {
      "text": "Flow message body"	// List body text
    },
    "footer": {
      "text": "Flow message footer"	// List footer text
    },
    "action": {
      "button": "Choose Option",	// List CTA button text
      "sections": [			// List sections
        {
          "title": "Fruits",		// List section title
          "rows": [			// List section rows
            {
              "id": "apple_id",
              "title": "Apple",
              "description": "Fresh red apple"
            },
            {
              "id": "banana_id",
              "title": "Banana",
              "description": "Sweet banana"
            }
          ]
        },
        {
          "title": "Vegetables",
          "rows": [
            {
              "id": "carrot_id",
              "title": "Carrot",
              "description": "Crunchy carrot"
            },
            {
              "id": "spinach_id",
              "title": "Spinach",
              "description": "Green spinach leaves"
            }
          ]
        }
      ]
    }
  }
}
```

###### 10. Interactive button message

```json
{
  "type": "interactive",
  "interactive": {
    "type": "button",
    "body": {
      "text": "Do you want to proceed?"
    },
    "action": {
      "buttons": [
        {
          "type": "reply",
          "reply": {
            "id": "yes_button",
            "title": "Yes"
          }
        },
        {
          "type": "reply",
          "reply": {
            "id": "no_button",
            "title": "No"
          }
        }
      ]
    }
  }
}
```
---

### Message status & responses

###### Example success response

```json
{
    "message": "Message sent successfully.",
    "error": false,
}
```

###### Example error response

```json
{
    "message": "Invalid WhatsApp number.",
    "error": true
}
```
