Wasend

Send Voice Message

Send a voice message to a WhatsApp contact

Send Voice Message

Send a voice message (audio note) to a WhatsApp contact.

Endpoint

POST /sendVoice

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")
urlstringNo*URL of the voice message to send
datastringNo*Base64 encoded voice message data

* Either url or data must be provided

Response

{
  "id": "string",
  "to": "string",
  "content": "string",
  "type": "ptt",
  "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 (e.g., audio URL/ref)
typestringType of the message (always "ptt")
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

# Send a voice message with URL
curl -X POST "https://api.wasend.dev/sendVoice" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "session": "sessionId",
    "to": "+1234567890",
    "url": "https://example.com/voice.mp3"
  }'

# Send a voice message with base64 data
curl -X POST "https://api.wasend.dev/sendVoice" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "session": "sessionId",
    "to": "+1234567890",
    "data": "base64_encoded_voice_data"
  }'
import { WasendClient } from '@wasend/core';

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

// Send a voice message with URL
const voiceMessage = await client.sendVoice({
  session: "sessionId",
  to: "+1234567890",
  url: "https://example.com/voice.mp3"
});

// Send a voice message with base64 data
const voiceData = "base64_encoded_voice_data";
const voiceMessage2 = await client.sendVoice({
  session: "sessionId",
  to: "+1234567890",
  data: voiceData
});
const { WasendClient } = require('@wasend/core');

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

// Send a voice message with URL
const voiceMessage = await client.sendVoice({
  session: "sessionId",
  to: "+1234567890",
  url: "https://example.com/voice.mp3"
});

// Send a voice message with base64 data
const voiceData = "base64_encoded_voice_data";
const voiceMessage2 = await client.sendVoice({
  session: "sessionId",
  to: "+1234567890",
  data: voiceData
});
from wasend import WasendClient

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

# Send a voice message with URL
voice_message = client.send_voice(
    session="sessionId",
    to="+1234567890",
    url="https://example.com/voice.mp3"
)

# Send a voice message with base64 data
voice_data = "base64_encoded_voice_data"
voice_message2 = client.send_voice(
    session="sessionId",
    to="+1234567890",
    data=voice_data
)
package main

import (
	"fmt"
	"log"
	"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 voice message with URL
	voiceMessage, err := client.SendVoice(&wasendcore.MessageVoiceRequest{
		Session: StringPtr("sessionId"),
		To:      StringPtr("+1234567890"),
		Url:     StringPtr("https://example.com/voice.mp3"),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Voice message sent: %+v\n", voiceMessage)

	// Send a voice message with base64 data
	voiceData := "base64_encoded_voice_data"
	voiceMessage2, err := client.SendVoice(&wasendcore.MessageVoiceRequest{
		Session: StringPtr("sessionId"),
		To:      StringPtr("+1234567890"),
		Data:    StringPtr(voiceData),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Voice message from base64 sent: %+v\n", voiceMessage2)
}
using Wasend.Core;

var config = new WasendConfig
{
    ApiKey = "YOUR_API_KEY"
};
var client = new WasendClient(config);

// Send a voice message with URL
var voiceMessage = client.SendVoice(new MessageVoiceRequest
{
    Session = "sessionId",
    To = "+1234567890",
    Url = "https://example.com/voice.mp3"
});

// Send a voice message with base64 data
var voiceData = "base64_encoded_voice_data";
var voiceMessage2 = client.SendVoice(new MessageVoiceRequest
{
    Session = "sessionId",
    To = "+1234567890",
    Data = voiceData
});
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import org.json.JSONObject;

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

        // Send a voice message with URL
        JSONObject requestBodyUrl = new JSONObject();
        requestBodyUrl.put("session", "sessionId");
        requestBodyUrl.put("to", "+1234567890");
        requestBodyUrl.put("url", "https://example.com/voice.mp3");

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

        HttpResponse<String> responseUrl = httpClient.send(requestUrl, HttpResponse.BodyHandlers.ofString());
        System.out.println("URL Voice Response: " + responseUrl.body());

        // Send a voice message with base64 data
        JSONObject requestBodyData = new JSONObject();
        requestBodyData.put("session", "sessionId");
        requestBodyData.put("to", "+1234567890");
        requestBodyData.put("data", "base64_encoded_voice_data");

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

        HttpResponse<String> responseData = httpClient.send(requestData, HttpResponse.BodyHandlers.ofString());
        System.out.println("Data Voice Response: " + responseData.body());
    }
}
<?php
$ch = curl_init();

// Send a voice message with URL
$voiceDataUrl = [
    'session' => 'sessionId',
    'to' => '+1234567890',
    'url' => 'https://example.com/voice.mp3'
];

curl_setopt($ch, CURLOPT_URL, "https://api.wasend.dev/sendVoice");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer YOUR_API_KEY",
    "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($voiceDataUrl));

$responseUrl = curl_exec($ch);
echo "URL Voice Response: " . $responseUrl . "\n";

// Send a voice message with base64 data
$voiceDataBase64 = [
    'session' => 'sessionId',
    'to' => '+1234567890',
    'data' => 'base64_encoded_voice_data'
];

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($voiceDataBase64));
$responseData = curl_exec($ch);
echo "Data Voice Response: " . $responseData . "\n";

curl_close($ch);
require 'net/http'
require 'uri'
require 'json'

uri = URI('https://api.wasend.dev/sendVoice')

# Send a voice message with URL
req_url = Net::HTTP::Post.new(uri)
req_url['Authorization'] = 'Bearer YOUR_API_KEY'
req_url['Content-Type'] = 'application/json'
req_url.body = {
  session: 'sessionId',
  to: '+1234567890',
  url: 'https://example.com/voice.mp3'
}.to_json

res_url = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(req_url)
end
puts "URL Voice Response: #{res_url.body}"

# Send a voice message with base64 data
req_data = Net::HTTP::Post.new(uri)
req_data['Authorization'] = 'Bearer YOUR_API_KEY'
req_data['Content-Type'] = 'application/json'
req_data.body = {
  session: 'sessionId',
  to: '+1234567890',
  data: 'base64_encoded_voice_data'
}.to_json

res_data = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(req_data)
end
puts "Data Voice Response: #{res_data.body}"
import Foundation

func sendVoiceMessage(urlString: String?, base64Data: String?) {
    guard let url = URL(string: "https://api.wasend.dev/sendVoice") else { return }
    var request = URLRequest(url: url)
    request.httpMethod = "POST"
    request.setValue("Bearer YOUR_API_KEY", forHTTPHeaderField: "Authorization")
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")

    var body: [String: Any] = [
        "session": "sessionId",
        "to": "+1234567890"
    ]
    if let urlString = urlString {
        body["url"] = urlString
    } else if let base64Data = base64Data {
        body["data"] = base64Data
    }

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

    URLSession.shared.dataTask(with: request) { data, response, error in
        if let data = data, let responseString = String(data: data, encoding: .utf8) {
            print("Voice Response: \(responseString)")
        }
    }.resume()
}

// Send voice message with URL
sendVoiceMessage(urlString: "https://example.com/voice.mp3", base64Data: nil)

// Send voice message with Base64 Data
sendVoiceMessage(urlString: nil, base64Data: "base64_encoded_voice_data")
use reqwest::Client;
use serde_json::json;

async fn send_voice_message(url_option: Option<&str>, data_option: Option<&str>) -> Result<String, reqwest::Error> {
    let client = Client::new();
    let mut body = json!({
        "session": "sessionId",
        "to": "+1234567890",
    });

    if let Some(url_val) = url_option {
        body["url"] = json!(url_val);
    } else if let Some(data_val) = data_option {
        body["data"] = json!(data_val);
    }

    client.post("https://api.wasend.dev/sendVoice")
        .header("Authorization", "Bearer YOUR_API_KEY")
        .header("Content-Type", "application/json")
        .json(&body)
        .send()
        .await?
        .text()
        .await
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Send voice message with URL
    let response_url = send_voice_message(Some("https://example.com/voice.mp3"), None).await?;
    println!("URL Voice Response: {}", response_url);

    // Send voice message with Base64 Data
    let response_data = send_voice_message(None, Some("base64_encoded_voice_data")).await?;
    println!("Data Voice Response: {}", response_data);

    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
  • Supported audio formats for voice notes: OGG (with opus codec), AAC, MP3 (may be transcoded)
  • Maximum audio duration: 60 seconds
  • Maximum file size: 16MB
  • For URL-based audio, the URL must be publicly accessible
  • For base64 data, the audio must be properly encoded
  • Voice messages are played as audio notes (PTT) in WhatsApp