Skip to content

WhatsApp

HTTP request to send via WhatsApp

The payload to send a WhatsApp message is as follows:

POST https://api.obmessage.ai/api/v1/whatsapp
Authorization: {{API_KEY}}
Content-Type: application/json
{
    "phone": "+18099999999",
    "reference": "219012",
    "group": "campid01",
    "whatsapp_template": {
        "name": "hello_world",
        "language": {
            "code": "en_US"
        }
    }
}

To request a WhatsApp integration, contact us by email.

Contact us

Required data

The following data is required:

Field Description
phone Phone number to which the WhatsApp message will be sent. It must be compatible with the E.164 recommendation.
whatsapp_template WhatsApp template data. Required only if template_id is not used.

whatsapp_template

The whatsapp_template object contains the information required to send the message according to the template configuration.

It uses the same structure documented by Meta in this link, with support for:

  • Sending body content with or without variables.
  • Sending headers with or without variables.
  • Sending headers with images, videos, and documents.
  • Sending messages with quick_reply buttons.
  • Sending messages with url buttons.

Variable replacement is also supported using variables defined in fields within OBMessage.

It is also possible to create the template with the same whatsapp_template data, so that each request only needs to include template_id instead of sending the full payload every time.

Examples

For examples that include variables, the template must be correctly configured in Meta. When a variable such as {{1}} is added in Meta, it means that the value replaced from OBMessage in parameters will be used.

The parameters values that can use OBMessage variables are:

  • image.link
  • video.link
  • document.link
  • text
  • payload

If variables are used, they must not be blank.

Send template without variables

{
    "phone": "+18099999999",
    "whatsapp_template": {
        "name": "hello_world",
        "language": {
            "code": "en_US"
        }
    }
}

To request a WhatsApp integration, contact us by email.

Contact us

Send template with variables

{
    "phone": "+18299999999",
    "fields": [
        {
            "name": "body_text",
            "value": "test"
        }
    ],
    "whatsapp_template": {
        "name": "prueba",
        "language": {
            "code": "es"
        },
        "components": [
            {
                "type": "body",
                "parameters": [
                    {
                        "type": "text",
                        "text": "{{body_text}} test"
                    }
                ]
            }
        ]
    }
}

To request a WhatsApp integration, contact us by email.

Contact us

Send template with buttons, headers, and body

{
    "phone": "+18099999999",
    "fields": [
        {
            "name": "header_text",
            "value": "test"
        },
        {
            "name": "body_text",
            "value": "test"
        },
        {
            "name": "btn_text_1",
            "value": "test"
        },
        {
            "name": "btn_text_2",
            "value": "logout"
        }
    ],
    "whatsapp_template": {
        "name": "prueba_header",
        "language": {
            "code": "es"
        },
        "components": [
            {
                "type": "header",
                "parameters": [
                    {
                        "type": "text",
                        "text": "nombre {{header_text}}"
                    }
                ]
            },
            {
                "type": "body",
                "parameters": [
                    {
                        "type": "text",
                        "text": "{{body_text}} test"
                    }
                ]
            },
            {
                "type": "button",
                "sub_type": "quick_reply",
                "index": 0,
                "parameters": [
                    {
                        "type": "payload",
                        "payload": "{{btn_text_1}}"
                    }
                ]
            },
            {
                "type": "button",
                "sub_type": "url",
                "index": 1,
                "parameters": [
                    {
                        "type": "text",
                        "text": "{{btn_text_2}}"
                    }
                ]
            }
        ]
    }
}

To request a WhatsApp integration, contact us by email.

Contact us

Send images, videos, and documents

For this case, the same payload is used. You only need to change image to video or document, as required.

{
    "phone": "+18099999999",
    "fields": [
        {
            "name": "image_link",
            "value": "https://dy9y48tmgyg6d.cloudfront.net/db931e22-1844-11ed-b9cc-000c2962f118/ceeb60c8-981a-4c33-96fd-4d532f72913d"
        }
    ],
    "whatsapp_template": {
        "name": "prueba_imagen",
        "language": {
            "code": "es"
        },
        "components": [
            {
                "type": "header",
                "parameters": [
                    {
                        "type": "image",
                        "image": {
                            "link": "{{image_link}}"
                        }
                    }
                ]
            }
        ]
    }
}

To request a WhatsApp integration, contact us by email.

Contact us