WhatsApp Business API

WhatsApp Business API in Morocco: send WhatsApp messages from your code

EnvoiSMS.ma's WhatsApp Business API sends your WhatsApp messages through the same REST endpoint as your SMS: POST /v1/messages with channel: "whatsapp", from your own connected WhatsApp Business number. Meta-approved templates, media, lists and buttons, replies inside the 24-hour window, delivery reports by webhook. Each message is billed in dirhams by category: to a Moroccan number, 0.65 MAD per notification and 0.90 MAD per marketing message, with no subscription.

One endpoint for SMS and WhatsApp

Already sending SMS? WhatsApp is the same call with one more field: POST https://api.envoisms.ma/v1/messages, header Authorization: Bearer <API key>, and channel: "whatsapp". The message leaves from your own WhatsApp Business number, connected in the dashboard. With no number connected, the API answers 403 WHATSAPP_NOT_CONNECTED and nothing is charged.

  • The same channel parameter in the official Node.js, PHP, Python and Go SDKs
  • An Idempotency-Key header makes every send safe to retry: a retry after a timeout never bills twice
  • JSON errors with a stable code (error.code) to branch on

Meta templates and the 24-hour window

A Meta-approved template can open a conversation at any time: it is exempt from the service window and priced by the category registered on your account. A free-form message (text, media, list…) is accepted only if the contact wrote to you on WhatsApp in the last 24 hours; otherwise the API answers 400 OUT_OF_24H_WINDOW before anything is charged.

  • template: { name, language, components } to start a conversation
  • 400 OUT_OF_24H_WINDOW carries window_expired and window_expires_at
  • Reactions are not billed

Rich messages: media, lists, buttons

The same endpoint carries every WhatsApp message type: text, media by id or by link, interactive messages (list, buttons, flow, URL button, location request), reactions, contact cards, locations and stickers, with a reply context to quote the customer's message.

  • interactive: list, button, flow, cta_url, location_request_message
  • Media by id (already uploaded) or by link
  • A reply context on any message type

Conversations, webhooks and OTP codes

GET /v1/conversations lists your threads with the expiry time of their 24-hour window, and POST /v1/messages/typing shows a typing indicator while you prepare the reply. Message statuses reach your webhooks signed with HMAC-SHA256 in the X-EnvoiSMS-Signature-256 header. For a one-time code on WhatsApp, POST /v1/verify/send with channel whatsapp goes through EnvoiSMS's shared sender: no number to connect.

  • Events message.sent, message.delivered, message.failed, message.undeliverable
  • Signature t=<timestamp>,v1=<hex>: reject any delivery older than 5 minutes
  • env_test_ sandbox keys: the whole path simulated, nothing delivered or debited

Everything you need to know about WhatsApp Business API.

Do I need to connect my own WhatsApp number to use the API?
Yes, to send messages with POST /v1/messages and channel: "whatsapp": they leave from your WhatsApp Business number connected in the dashboard. Without one, the API answers 403 WHATSAPP_NOT_CONNECTED and charges nothing. Only OTP codes (POST /v1/verify/send with channel whatsapp) go through EnvoiSMS's shared sender with no connection.
What happens if I send a free-form message outside the 24-hour window?
The API refuses it with 400 OUT_OF_24H_WINDOW before anything is charged. Send a Meta-approved template instead: it opens a conversation at any time.
Do message templates need to be approved by Meta?
Yes. To start a conversation you use a template approved by Meta. The console lets you submit your templates and follow their approval.
Can a message fall back to SMS if the recipient has no WhatsApp?
Yes: add cascade: true to a WhatsApp send and the message goes out as SMS if the number is unreachable or has no WhatsApp. A message type SMS cannot carry (media, buttons…) is refused with CASCADE_NOT_SUPPORTED. For an ordinary text to a customer, the default SMS channel remains the right choice.
How is a WhatsApp message billed?
Per message, in dirhams, by the template's category and the recipient's country, debited from your prepaid balance with no subscription. Current prices are on the pricing page.