Wasend

Send Message with Link Preview

Send a text message with a custom link preview to a WhatsApp contact

Send Message with Link Preview

Send a text message with a custom link preview to a WhatsApp contact. This allows you to customize how links appear in WhatsApp messages.

Endpoint

POST /sendLinkCustomPreview

Headers

NameTypeRequiredDescription
AuthorizationstringYesBearer token for authentication
Content-TypestringYesapplication/json

Request Body

FieldTypeRequiredDescription
sessionstringYesThe session ID
tostringYesRecipient's phone number in international format (e.g., "+1234567890")
textstringYesThe message text containing the URL
previewLinkPreviewRequestYesThe link preview information

LinkPreviewRequest Object

FieldTypeRequiredDescription
titlestringYesTitle for the link preview
descriptionstringNoDescription for the link preview
thumbnailUrlstringNoURL of the preview image

Response

{
  "id": "string",
  "to": "string",
  "content": "string",
  "type": "text",
  "timestamp": "string",
  "status": "string",
  "fromMe": boolean,
  "sender": "string",
  "recipient": "string"
}

Response Fields

FieldTypeDescription
idstringUnique identifier for the message
tostringThe recipient's phone number or group JID
contentstringContent of the message (the text sent)
typestringType of the message (always "text")
timestampstringWhen the message was sent
statusstringCurrent status of the message
fromMebooleanWhether the message was sent by you
senderstringSender's phone number
recipientstringThe message recipient (details may vary)

Examples

curl -X POST "https://api.wasend.dev/sendLinkCustomPreview" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "session": "sessionId",
    "to": "+1234567890",
    "text": "Check out our website: https://example.com",
    "preview": {
      "title": "Example Website",
      "description": "Visit our website for more information",
      "thumbnailUrl": "https://example.com/preview.jpg"
    }
  }'
import { WasendClient } from '@wasend/core';

const client = new WasendClient({
  apiKey: 'YOUR_API_KEY',
  baseUrl: 'https://api.wasend.dev'
});

// Send a message with custom link preview
const message = await client.sendLinkCustomPreview({
  session: "sessionId",
  to: "+1234567890",
  text: "Check out our website: https://example.com",
  preview: {
    title: "Example Website",
    description: "Visit our website for more information",
    thumbnailUrl: "https://example.com/preview.jpg"
  }
});
const { WasendClient } = require('@wasend/core');

const client = new WasendClient({
  apiKey: 'YOUR_API_KEY',
  baseUrl: 'https://api.wasend.dev'
});

// Send a message with custom link preview
const message = await client.sendLinkCustomPreview({
  session: "sessionId",
  to: "+1234567890",
  text: "Check out our website: https://example.com",
  preview: {
    title: "Example Website",
    description: "Visit our website for more information",
    thumbnailUrl: "https://example.com/preview.jpg"
  }
});
from wasend import WasendClient

client = WasendClient(
    api_key='YOUR_API_KEY',
    base_url='https://api.wasend.dev'
)

# Send a message with custom link preview
message = client.send_link_custom_preview(
    session="sessionId",
    to="+1234567890",
    text="Check out our website: https://example.com",
    preview={
        "title": "Example Website",
        "description": "Visit our website for more information",
        "thumbnailUrl": "https://example.com/preview.jpg"
    }
)
package main

import (
	"fmt"
	"github.com/wasenddev/wasend-sdk-go/wasendcore"
)

func StringPtr(s string) *string    { return &s }

func main() {
	client := wasendcore.NewWasendClient(&wasendcore.WasendConfig{
		ApiKey:  StringPtr("YOUR_API_KEY"),
		BaseUrl: StringPtr("https://api.wasend.dev"),
	})

	// Send a message with custom link preview
	message := client.SendLinkCustomPreview(&wasendcore.MessageLinkCustomPreviewRequest{
		Session: StringPtr("sessionId"),
		To:      StringPtr("+1234567890"),
		Text:    StringPtr("Check out our website: https://example.com"),
		Preview: &wasendcore.LinkPreviewRequest{
			Title:       StringPtr("Example Website"),
			Description: StringPtr("Visit our website for more information"),
			ThumbnailURL: StringPtr("https://example.com/preview.jpg"),
		},
	})
	fmt.Printf("Message with link preview sent: %+v\n", message)
}
using Wasend.Core;

var config = new WasendConfig
{
    ApiKey = "YOUR_API_KEY"
};

var client = new WasendClient(config);

// Send a message with custom link preview
var message = client.SendLinkCustomPreview(new MessageLinkCustomPreviewRequest
{
    Session = "sessionId",
    To = "+1234567890",
    Text = "Check out our website: https://example.com",
    Preview = new LinkPreviewRequest
    {
        Title = "Example Website",
        Description = "Visit our website for more information",
        ThumbnailUrl = "https://example.com/preview.jpg"
    }
});
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
import org.json.JSONObject;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        JSONObject previewObject = new JSONObject();
        previewObject.put("title", "Example Website");
        previewObject.put("description", "Visit our website for more information");
        previewObject.put("thumbnailUrl", "https://example.com/preview.jpg");
        
        JSONObject requestBody = new JSONObject();
        requestBody.put("session", "sessionId");
        requestBody.put("to", "+1234567890");
        requestBody.put("text", "Check out our website: https://example.com");
        requestBody.put("preview", previewObject);

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.wasend.dev/sendLinkCustomPreview"))
            .header("Authorization", "Bearer YOUR_API_KEY")
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(requestBody.toString()))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println("Response: " + response.body());
    }
}
<?php

$url = 'https://api.wasend.dev/sendLinkCustomPreview';
$data = [
    'session' => 'sessionId',
    'to' => '+1234567890',
    'text' => 'Check out our website: https://example.com',
    'preview' => [
        'title' => 'Example Website',
        'description' => 'Visit our website for more information',
        'thumbnailUrl' => 'https://example.com/preview.jpg'
    ]
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
    'Content-Type: application/json'
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;

?>
require 'net/http'
require 'json'
require 'uri'

uri = URI('https://api.wasend.dev/sendLinkCustomPreview')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer YOUR_API_KEY'
request['Content-Type'] = 'application/json'

request.body = {
  session: 'sessionId',
  to: '+1234567890',
  text: 'Check out our website: https://example.com',
  preview: {
    title: 'Example Website',
    description: 'Visit our website for more information',
    thumbnailUrl: 'https://example.com/preview.jpg'
  }
}.to_json

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end

puts response.body
import Foundation

let url = URL(string: "https://api.wasend.dev/sendLinkCustomPreview")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer YOUR_API_KEY", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

let body: [String: Any] = [
    "session": "sessionId",
    "to": "+1234567890",
    "text": "Check out our website: https://example.com",
    "preview": [
        "title": "Example Website",
        "description": "Visit our website for more information",
        "thumbnailUrl": "https://example.com/preview.jpg"
    ]
]

request.httpBody = try? JSONSerialization.data(withJSONObject: body)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()
use reqwest;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    
    let response = client
        .post("https://api.wasend.dev/sendLinkCustomPreview")
        .header("Authorization", "Bearer YOUR_API_KEY")
        .header("Content-Type", "application/json")
        .json(&json!({
            "session": "sessionId",
            "to": "+1234567890",
            "text": "Check out our website: https://example.com",
            "preview": {
                "title": "Example Website",
                "description": "Visit our website for more information",
                "thumbnailUrl": "https://example.com/preview.jpg"
            }
        }))
        .send()
        .await?
        .text()
        .await?;

    println!("Response: {}", response);
    Ok(())
}

Error Codes

CodeDescription
400Bad Request - Invalid parameters
401Unauthorized - Invalid or missing API key
404Not Found - Session or recipient not found
429Too many requests - Rate limit exceeded
500Internal server error

Notes

  • Phone numbers must be in international format (e.g., "+1234567890")
  • The @c.us suffix is automatically added by the API
  • The text field must contain the URL that you want to preview.
  • The preview.title is mandatory.
  • preview.description and preview.thumbnailUrl are optional.
  • Ensure preview.thumbnailUrl is a direct link to an image (JPEG, PNG).