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.
API Domain and Value
api_domain | Value |
---|---|
IN pod | api.in.kaleyra.io |
SG Pod | api.kaleyra.io |
EU Pod | api.eu.kaleyra.io |
NA pod | api.na.kaleyra.ai |
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_domain>/<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.in.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? |
---|---|---|---|---|
| String | Account SID (Security Identifier) | HXAP16XXXXXX97IN | Yes |
| String | Your API Key generated by Kaleyra.io. | Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3 | Yes |
| 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 |
| String | Message format for the message. | text | Yes |
| String | Content of the message. You must include the link of the web page here. | Hi, your order has been shipped. | Yes |
| String | Channel on which message must be sent. | Yes | |
| 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 |
| 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. | No | |
| String | The URL you want to include in the message | True | Yes |
| 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 7 days ago