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:
- 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. - 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:
curl -X POST \ 'https://api.kaleyra.io/v1/<sid>/messages' \
--header 'api-key: <api_key>' \
--form 'to= <to>' \
--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_url>' \
--form 'lang_code= <lang_code>'
Sample Request Format
The following is the sample request format to display the preview of the URL:
curl -X POST \ 'https://api.kaleyra.io/v1/HXAP16XXXXXX97IN/messages' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx3' \
--form 'to="91XXXXXXXXXX"' \
--form 'type="text"' \
--form 'body="Hi, Your order has been shipped."' \
--form 'channel="whatsapp"' \
--form 'from="91XXXXXXXXXX"' \
--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:
Parameter | Data Type | Description | Examples | Mandatory? |
---|---|---|---|---|
sid | String | Account SID (Security Identifier) | HXAP16XXXXXX97IN | Yes |
api_key | String | Your API Key generated by Kaleyra.io. | Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3 | Yes |
to_number | String | A 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. | 91XXXXXXXXXX | Yes |
message_type | String | Message format for the message. | text | Yes |
body_text | String | Content of the message. You must include the link of the web page here. | Hi, your order has been shipped. | Yes |
channel_name | String | Channel on which message must be sent. | Yes | |
from_number | String | The 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). | 91XXXXXXXXXX | Yes |
callback_url | String | Specifies 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-53a476b9a2f9 | No |
preview_url | String | The URL you want to include in the message | True | Yes |
language_code | String | The language in which, you want to preview the URL. | en | Yes |
Sample Success Response
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": {}
}
Updated about 1 month ago