Send File Message
Send a file message to a WhatsApp contact
Send File Message
Send a file (document) message to a WhatsApp contact.
Endpoint
POST /sendFile
Headers
Name | Type | Required | Description |
---|---|---|---|
Authorization | string | Yes | Bearer token for authentication |
Content-Type | string | Yes | application/json |
Request Body
Field | Type | Required | Description |
---|---|---|---|
session | string | Yes | The session ID |
to | string | Yes | Recipient's phone number in international format (e.g., "+1234567890") |
url | string | No* | URL of the file to send |
data | string | No* | Base64 encoded file data |
fileName | string | Yes | Name of the file |
mimeType | string | Yes | MIME type of the file (e.g., "application/pdf") |
* Either url
or data
must be provided
Response
{
"id": "string",
"to": "string",
"content": "string",
"type": "document",
"timestamp": "string",
"status": "string",
"fromMe": boolean,
"sender": "string",
"recipient": "string"
}
Response Fields
Field | Type | Description |
---|---|---|
id | string | Unique identifier for the message |
to | string | The recipient's phone number or group JID |
content | string | Content of the message (e.g., file URL/ref) |
type | string | Type of the message (always "document") |
timestamp | string | When the message was sent |
status | string | Current status of the message |
fromMe | boolean | Whether the message was sent by you |
sender | string | Sender's phone number |
recipient | string | The message recipient (details may vary) |
Examples
# Send a file with URL
curl -X POST "https://api.wasend.dev/sendFile" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"session": "sessionId",
"to": "+1234567890",
"url": "https://example.com/document.pdf",
"fileName": "document.pdf",
"mimeType": "application/pdf"
}'
# Send a file with base64 data
curl -X POST "https://api.wasend.dev/sendFile" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"session": "sessionId",
"to": "+1234567890",
"data": "base64_encoded_file_data",
"fileName": "document.pdf",
"mimeType": "application/pdf"
}'
import { WasendClient } from '@wasend/core';
const client = new WasendClient({
apiKey: 'YOUR_API_KEY',
baseUrl: 'https://api.wasend.dev'
});
// Send a file with URL
const fileMessage = await client.sendFile({
session: "sessionId",
to: "+1234567890",
url: "https://example.com/document.pdf",
fileName: "document.pdf",
mimeType: "application/pdf"
});
// Send a file with base64 data
const fileData = "base64_encoded_file_data";
const fileMessage2 = await client.sendFile({
session: "sessionId",
to: "+1234567890",
data: fileData,
fileName: "document.pdf",
mimeType: "application/pdf"
});
const { WasendClient } = require('@wasend/core');
const client = new WasendClient({
apiKey: 'YOUR_API_KEY',
baseUrl: 'https://api.wasend.dev'
});
// Send a file with URL
const fileMessage = await client.sendFile({
session: "sessionId",
to: "+1234567890",
url: "https://example.com/document.pdf",
fileName: "document.pdf",
mimeType: "application/pdf"
});
from wasend import WasendClient
client = WasendClient(
api_key='YOUR_API_KEY',
base_url='https://api.wasend.dev'
)
# Send a file with URL
file_message = client.send_file(
session="sessionId",
to="+1234567890",
url="https://example.com/document.pdf",
file_name="document.pdf",
mime_type="application/pdf"
)
package main
import (
"fmt"
"github.com/wasenddev/wasend-sdk-go/wasendcore"
)
func StringPtr(s string) *string {
return &s
}
func Float64Ptr(f float64) *float64 {
return &f
}
func main() {
config := wasendcore.WasendConfig{
ApiKey: StringPtr("YOUR_API_KEY"),
BaseUrl: StringPtr("https://api.wasend.dev"),
}
client := wasendcore.NewWasendClient(config)
// Send a file with URL
fileMessage := client.SendFile(&wasendcore.MessageFileRequest{
Session: StringPtr("sessionId"),
To: StringPtr("+1234567890"),
URL: StringPtr("https://example.com/document.pdf"),
FileName: StringPtr("document.pdf"),
MimeType: StringPtr("application/pdf"),
})
fmt.Printf("File message sent: %+v\n", fileMessage)
// Send a file with base64 data
fileData := "base64_encoded_file_data"
fileMessage2 := client.SendFile(&wasendcore.MessageFileRequest{
Session: StringPtr("sessionId"),
To: StringPtr("+1234567890"),
Data: StringPtr(fileData),
FileName: StringPtr("document.pdf"),
MimeType: StringPtr("application/pdf"),
})
fmt.Printf("File message from base64 sent: %+v\n", fileMessage2)
}
using Wasend.Core;
var config = new WasendConfig
{
ApiKey = "YOUR_API_KEY"
// BaseUrl is optional, defaults to https://api.wasend.dev
};
var client = new WasendClient(config);
// Send a file with URL
var fileMessage = client.SendFile(new MessageFileRequest
{
Session = "sessionId",
To = "+1234567890",
Url = "https://example.com/document.pdf",
FileName = "document.pdf",
MimeType = "application/pdf"
});
// Send a file with base64 data
var fileData = "base64_encoded_file_data";
var fileMessage2 = client.SendFile(new MessageFileRequest
{
Session = "sessionId",
To = "+1234567890",
Data = fileData,
FileName = "document.pdf",
MimeType = "application/pdf"
});
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();
// Send a file with URL
JSONObject requestBody = new JSONObject();
requestBody.put("session", "sessionId");
requestBody.put("to", "+1234567890");
requestBody.put("url", "https://example.com/document.pdf");
requestBody.put("fileName", "document.pdf");
requestBody.put("mimeType", "application/pdf");
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.wasend.dev/sendFile"))
.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/sendFile';
$data = [
'session' => 'sessionId',
'to' => '+1234567890',
'url' => 'https://example.com/document.pdf',
'fileName' => 'document.pdf',
'mimeType' => 'application/pdf'
];
$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/sendFile')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer YOUR_API_KEY'
request['Content-Type'] = 'application/json'
request.body = {
session: 'sessionId',
to: '+1234567890',
url: 'https://example.com/document.pdf',
fileName: 'document.pdf',
mimeType: 'application/pdf'
}.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/sendFile")!
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",
"url": "https://example.com/document.pdf",
"fileName": "document.pdf",
"mimeType": "application/pdf"
]
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/sendFile")
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "application/json")
.json(&json!({
"session": "sessionId",
"to": "+1234567890",
"url": "https://example.com/document.pdf",
"fileName": "document.pdf",
"mimeType": "application/pdf"
}))
.send()
.await?
.text()
.await?;
println!("Response: {}", response);
Ok(())
}
Error Codes
Code | Description |
---|---|
400 | Bad Request - Invalid parameters |
401 | Unauthorized - Invalid or missing API key |
404 | Not Found - Session or recipient not found |
429 | Too many requests - Rate limit exceeded |
500 | Internal server error |
Notes
- Phone numbers must be in international format (e.g., "+1234567890")
- The @c.us suffix is automatically added by the API
- Supported file types: PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, TXT, CSV
- Maximum file size: 100MB
- For URL-based files, the URL must be publicly accessible
- For base64 data, the file must be properly encoded