Preview of the URL

POST Method

When you send a link in the message, the Preview URL parameter will display the preview of the landing page associated with that link. You have to add the preview_url parameter and set the value as True in the request.

📘

Note:

The preview of the URL is only supported for the non-template type (text) of messages.


To display the preview of the URL, perform the following steps:

  1. Before you get started, Create an API Key. To view the API Key and the SID, see View API Key and SID.
    A prerequisite for using Kaleyra WhatsApp APIs is to have an active WhatsApp plan on kaleyra.io.
  2. To set up a WhatsApp account on kaleyra.io, see: Manual Signup and Embedded Signup.

Base URL

https://<api_domain>/v2/<SID>


API request to Preview the URL

To display the preview of the URL, use the /messages endpoint.

Request Format

The following is the request format to display the preview of the URL:

--location --request POST 'https://api.kaleyra.io/v1/<SID>/messages' \
--header 'api-key: <api_key>' \
--form 'to="<to_number>"' \
--form 'type="<message_type>"' \
--form 'body="<body_text>"' \
--form 'channel="<channel_name>"' \
--form 'from="<from_number>"' \
--form 'callback_url="<callback_url>"' \
--form 'preview_url="<preview>"' \
--form 'lang_code="<language_code>"'

Sample Request Format

The following is the sample request format to display the preview of the URL:

--location --request POST 'https://api.kaleyra.io/v1/HXAP16XXXXXX97IN/messages' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx3' \
--form 'to="9193XXXXXXX6"' \
--form 'type="text"' \
--form 'body="Hi, Your order has been shipped."' \
--form 'channel="whatsapp"' \
--form 'from="91806XXXXXX8"' \
--form 'callback_url="https://trees.free.beeceptor.com"' \
--form 'preview_url="True"' \
--form 'lang_code="en"'

Parameter and Data Types

The following is the list of parameters and data types supported to display the preview of the URL:

ParameterData TypeDescriptionExamplesMandatory?
sidStringAccount SID (Security Identifier)HXAP16XXXXXX97INYes
api_keyStringYour API Key generated by Kaleyra.io.Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3Yes
to_numberStringA valid WhatsApp number of the recipient. Ensure that the country code is prefixed to the number. (E164 format).

Note: You can add multiple recipients, separate each number using the comma (,) delimiter.
91XXXXXXXXXXYes
message_typeStringMessage format for the message.textYes
body_textStringContent of the message. You must include the link of the web page here.Hi, your order has been shipped.Yes
channel_nameStringChannel on which message must be sent.WhatsAppYes
from_numberStringThe number registered with WhatsApp business from which the message is to be sent. Ensure that the country code is prefixed to the number. (E164 format).91XXXXXXXXXXYes
callback_urlStringSpecifies the callback URL to receive notifications regarding the WhatsApp message status (sent, delivered, read, and failed). For more information related to callback profiles, see the Callback profiles page.
The URL can be accessed publicly.
Click here for an example.
https://webhook.site/4e196e4c-cf5d-43c7-aaec-53a476b9a2f9No
preview_urlStringThe URL you want to include in the messageTrueYes
language_codeStringThe language in which, you want to preview the URL.enYes

Sample Success Response

The following success message appears with the status 202 Accepted:

202 Accepted 
{
"code":"WA202"
"message":"Request Accepted",
"data":{
  "message_id":"AXXXXXXXXXXXXXXXXXXX"
}
"error":{}
}

The following success message appears with status 202 Accepted:

{
    "id": "bae7XXX8-4ad5-4eXX-a60f-6ce60aXXXX39",
    "type": "text",
    "body": "https://www.facebook.com/KaleyraPlatform",
    "createdDateTime": "2020-10-12 10:40:32+00:00",
    "totalCount": 1,
    "data": [
        {
            "message_id": "bae79XXX-4ad5-4eXX-a60f-6ce60a3XXXX9:0",
            "recipient": "91xxxxxxxxxx"
        }
    ],
    "error": {}
}