The API
Sending Media Message

Sending Media Messages

Endpoint

To send a media message, make a POST request to the following endpoint:

URL: /whatsapp/send-message

Request Headers

Include the API key as an Authorization header using the Bearer token scheme.

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

The request body should contain the following parameters:

  • phoneNumber (string, required): The recipient's phone number in international format (e.g., +254712345678).
  • mediaUrl (string, required): The url to the media to be sent.
  • type (string, required, value:media): The type of message, which, in this case, should be set to media.
  • fileName (string, optional): The filename of the media, should include the file extension matching the media file type. Optional for images and vedio type.
  • media_type (string, required, value:image || document): The type of media to be sent. allowed media types
    1. image
    2. document
  • message (string, optional): This will serve as a caption message if provided. You can include line breakers (\n) for formatting.

Example Request

  • POST /whatsapp/send-message
  • Authorization: Bearer YOUR_API_KEY
  • Content-Type: application/json
{
    "phoneNumber": "+254712345678",
    "message": "This as a caption message.",
    "type": "media",
    "media_type": "image",
    "fileName": "filename.pdf",
    "mediaUrl":"https://www.africau.edu/images/default/sample.pdf"
}

allowed media types

  1. image
  2. document

Successful Response

If the message is sent successfully, you will receive the following response:

{
    "message": "Message sent successfully"
}

Error Responses

If there are any errors in the request, you will receive one of the following error responses:

  1. "Invalid phone number": The provided phone number is not in the correct international format.
  2. "Phone number not registered on WhatsApp": The recipient's phone number is not registered on WhatsApp.
  3. "Missing required inputs": One or more required parameters are missing in the request.