🚀 NextMavens WhatsApp API

Production-ready WhatsApp Business API with multi-tenant authentication

Base URL: https://whatsapp.nextmavens.cloud

🔐 Authentication

All API requests require your API key in the request header:

apikey: YOUR_NEXTMAVENS_API_KEY
⚠️ IMPORTANT: Your API key is issued by NextMavens upon account creation. Keep it secret. Do not expose it in client-side code or public repositories.

📱 Instance Management

An 'instance' represents one WhatsApp phone number connection. Each company can have multiple instances — one per phone number they want to use.

1.1 Create an Instance

POST /instance/create

{
  "instanceName": "mycompany-sales",
  "integration": "WHATSAPP-BAILEYS",
  "qrcode": true,
  "number": "",
  "token": "optional-custom-token"
}
⚠️ WARNING: Save the hash.apikey value from the response. This is the per-instance token used for all subsequent calls to this instance. It is different from your global API key.

1.2 Get QR Code (for reconnection)

GET /instance/connect/{instanceName}

Use when instance is disconnected and user needs to re-scan QR.

1.3 Check Instance Status

GET /instance/connectionState/{instanceName}

StatusMeaning
openConnected and ready to send/receive messages
connectingQR was scanned, waiting for full connection
closeDisconnected — user needs to re-scan QR code
refusedConnection was refused by WhatsApp servers

1.4 Fetch All Instances

GET /instance/fetchInstances

1.5 Delete an Instance

DELETE /instance/delete/{instanceName}

⚠️ WARNING: Deleting an instance removes the WhatsApp session permanently. The phone number can be reconnected by creating a new instance.

💬 Sending Messages

⚠️ WARNING: Always check that instance status is 'open' before sending messages. Sending to a disconnected instance returns a 400 error.

2.1 Send Text Message

POST /message/sendText/{instanceName}

{
  "number": "254712345678",
  "text": "Hello from NextMavens API!",
  "delay": 1200
}

Parameters:

2.2 Send Image

POST /message/sendMedia/{instanceName}

{
  "number": "254712345678",
  "mediatype": "image",
  "mimetype": "image/jpeg",
  "caption": "Check this out!",
  "media": "https://example.com/image.jpg",
  "delay": 2000
}

2.3 Send Document / PDF

{
  "number": "254712345678",
  "mediatype": "document",
  "mimetype": "application/pdf",
  "caption": "Invoice #1234",
  "fileName": "invoice_1234.pdf",
  "media": "BASE64_ENCODED_PDF_DATA"
}

2.4 Send Audio (Voice Note)

{
  "number": "254712345678",
  "audio": "BASE64_ENCODED_AUDIO",
  "encoding": true
}
💡 NOTE: For audio, always send pure base64 without the data:audio/ogg;base64, prefix. Set encoding: true so Evolution API converts it to WhatsApp's PTT format.

2.5 Send Buttons (Interactive)

POST /message/sendButtons/{instanceName}

{
  "number": "254712345678",
  "title": "Choose an option",
  "description": "Please select below:",
  "footer": "NextMavens",
  "buttons": [
    { "type": "reply", "displayText": "Yes", "id": "btn_yes" },
    { "type": "reply", "displayText": "No", "id": "btn_no" }
  ]
}

🔔 Webhooks — Real-Time Events

Configure webhooks to receive real-time events (incoming messages, status updates, QR code changes) on your server.

3.1 Set Webhook for an Instance

POST /webhook/set/{instanceName}

{
  "enabled": true,
  "url": "https://yourapp.com/webhook/whatsapp",
  "webhookByEvents": false,
  "webhookBase64": false,
  "events": [
    "MESSAGES_UPSERT",
    "MESSAGES_UPDATE",
    "CONNECTION_UPDATE",
    "QRCODE_UPDATED",
    "SEND_MESSAGE"
  ]
}

3.2 Webhook Event Reference

EventTriggered When
MESSAGES_UPSERTA new message is received or sent
MESSAGES_UPDATEA message status changes (sent, delivered, read)
CONNECTION_UPDATEInstance connects, disconnects, or QR is scanned
QRCODE_UPDATEDA new QR code is generated (e.g., on session expiry)
SEND_MESSAGEA message is sent from the instance
PRESENCE_UPDATEA contact's online/typing status changes
CONTACTS_UPSERTContact list is synced or updated

3.3 Sample Incoming Message Webhook Payload

{
  "event": "messages.upsert",
  "instance": "mycompany-sales",
  "data": {
    "key": {
      "remoteJid": "254712345678@s.whatsapp.net",
      "fromMe": false,
      "id": "3EB0A12345ABCDEF"
    },
    "pushName": "John Doe",
    "message": {
      "conversation": "Hello! I need help with my order."
    },
    "messageTimestamp": 1714000000,
    "messageType": "conversation"
  }
}

👥 Contact & Chat Management

4.1 Check if Number Exists on WhatsApp

POST /chat/whatsappNumbers/{instanceName}

{
  "numbers": ["254712345678", "254700112233"]
}
💡 NOTE: Always verify numbers before bulk sending. Sending to non-WhatsApp numbers does not cause issues, but it wastes your rate limit quota and can increase spam signals.

4.2 Fetch Chat History

POST /chat/findMessages/{instanceName}

{
  "where": {
    "key": { "remoteJid": "254712345678@s.whatsapp.net" }
  },
  "limit": 50
}

4.3 Mark Messages as Read

POST /chat/markMessageAsRead/{instanceName}

{
  "readMessages": [
    { "remoteJid": "254712345678@s.whatsapp.net", "fromMe": false, "id": "MESSAGE_ID" }
  ]
}

4.4 Get Profile Picture URL

GET /chat/fetchProfilePictureUrl/{instanceName}?number=254712345678

👥 Group Management

5.1 Create a Group

POST /group/create/{instanceName}

{
  "subject": "Team Updates",
  "description": "Company-wide announcements",
  "participants": ["254712345678", "254700112233"]
}

5.2 Send Message to Group

POST /message/sendText/{instanceName}

{
  "number": "120363XXXXXXXXXX@g.us",
  "text": "Hello team!"
}

Use the group JID, not a phone number.

5.3 Fetch All Groups

GET /group/fetchAllGroups/{instanceName}?getParticipants=false

⚠️ Error Codes & Troubleshooting

CodeErrorResolution
400Bad RequestCheck your request body — missing or invalid field
401UnauthorizedMissing apikey header in your request
403ForbiddenYour API key is invalid or deactivated — contact support
404Instance not foundThe instanceName in your URL doesn't exist — check spelling
409Instance existsAn instance with this name already exists — use fetchInstances to check
429Rate limit exceededSlow down your requests — respect the delay parameter
500Internal errorServer error — check with NextMavens support; include your instance name

📦 Complete Integration Flow

Here is the complete flow from receiving API credentials to sending your first message:

  1. Receive your API key from NextMavens via email/dashboard
  2. Create an instance: POST /instance/create with instanceName
  3. Display the QR code (base64 image) to the end user in your app
  4. User scans QR with their WhatsApp mobile app
  5. Poll GET /instance/connectionState/{instanceName} until status === 'open'
  6. Store the instance token (from create response hash.apikey) in your database
  7. Configure a webhook: POST /webhook/set/{instanceName}
  8. Send messages using the instanceName in the URL path
  9. Handle incoming messages via your webhook endpoint
  10. Monitor connection status — if 'close', prompt user to re-scan QR
✅ TIP: For production applications, use WebSockets (Evolution API supports them at /ws) instead of polling for connection status. This is more efficient and gives instant connection updates.

Quick Example: First Message

# 1. Create instance
curl -X POST https://whatsapp.nextmavens.cloud/instance/create \
  -H 'apikey: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "instanceName": "test-instance",
    "integration": "WHATSAPP-BAILEYS",
    "qrcode": true
  }'

# 2. Save the returned hash.apikey (instance token)

# 3. Wait for user to scan QR, then check status
curl -H 'apikey: YOUR_API_KEY' \
  https://whatsapp.nextmavens.cloud/instance/connectionState/test-instance

# 4. Send a message (use instance token as apikey)
curl -X POST https://whatsapp.nextmavens.cloud/message/sendText/test-instance \
  -H 'apikey: INSTANCE_TOKEN_FROM_STEP_2' \
  -H 'Content-Type: application/json' \
  -d '{
    "number": "254712345678",
    "text": "Hello!",
    "delay": 1500
  }'

✅ WhatsApp Best Practices

To avoid WhatsApp account bans, follow these critical rules:

See WHATSAPP_BEST_PRACTICES.md in the project repository for complete guidelines.

📋 Quick Reference Card

─── INSTANCES ───────────────────────────────────
POST/instance/createCreate new instance + QR
GET/instance/connect/{name}Get QR code (reconnect)
GET/instance/connectionState/{name}Get connection status
GET/instance/fetchInstancesList all instances
DELETE/instance/delete/{name}Delete instance
PUT/instance/restart/{name}Restart instance
PUT/instance/logout/{name}Log out (removes session)
─── MESSAGES ────────────────────────────────────
POST/message/sendText/{name}Send text message
POST/message/sendMedia/{name}Send image/video/document
POST/message/sendWhatsAppAudio/{name}Send voice note
POST/message/sendButtons/{name}Send interactive buttons
POST/message/sendList/{name}Send list message
POST/message/sendLocation/{name}Send location pin
DELETE/message/delete/{name}Delete sent message
─── CHAT & CONTACTS ──────────────────────────────
POST/chat/whatsappNumbers/{name}Verify numbers on WhatsApp
POST/chat/findMessages/{name}Fetch chat history
POST/chat/markMessageAsRead/{name}Mark messages as read
GET/chat/fetchProfilePictureUrl/{name}Get profile picture
─── GROUPS ──────────────────────────────────────
POST/group/create/{name}Create a group
GET/group/fetchAllGroups/{name}List all groups
PUT/group/updateParticipant/{name}Add/remove participants
─── WEBHOOK ─────────────────────────────────────
POST/webhook/set/{name}Configure webhook
GET/webhook/find/{name}Get webhook config

Base URL: https://whatsapp.nextmavens.cloud | Auth Header: apikey: YOUR_KEY

🔧 Evolution Manager Web UI

Evolution API ships with a built-in web interface for admin management.

The manager lets you visually: