Upload an attachment to R2 storage (tiered auth)
curl --request POST \
--url https://your-instance.example.com/api/messages/upload-attachment \
--header 'Content-Type: multipart/form-data' \
--form file='@example-file' \
--form webchatConfigId=64a1b2c3d4e5f60012345678import requests
url = "https://your-instance.example.com/api/messages/upload-attachment"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "webchatConfigId": "64a1b2c3d4e5f60012345678" }
response = requests.post(url, data=payload, files=files)
print(response.text)const form = new FormData();
form.append('file', '<binary: receipt.png>');
form.append('webchatConfigId', '64a1b2c3d4e5f60012345678');
const options = {method: 'POST'};
options.body = form;
fetch('https://your-instance.example.com/api/messages/upload-attachment', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://your-instance.example.com/api/messages/upload-attachment",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<binary: receipt.png>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webchatConfigId\"\r\n\r\n64a1b2c3d4e5f60012345678\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://your-instance.example.com/api/messages/upload-attachment"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<binary: receipt.png>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webchatConfigId\"\r\n\r\n64a1b2c3d4e5f60012345678\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://your-instance.example.com/api/messages/upload-attachment")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<binary: receipt.png>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webchatConfigId\"\r\n\r\n64a1b2c3d4e5f60012345678\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://your-instance.example.com/api/messages/upload-attachment")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<binary: receipt.png>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webchatConfigId\"\r\n\r\n64a1b2c3d4e5f60012345678\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"success": true,
"attachment": {
"storageKey": "messages/65a0e0e0e0e0e0e0e0e0e0e0/msg_67b0/photo.jpg",
"filename": "photo.jpg",
"contentType": "image/jpeg",
"size": 184221
}
}{
"error": "Attachment not found",
"message": "Attachment not found"
}{
"error": "Attachment not found",
"message": "Attachment not found"
}{
"error": "Too many requests",
"limit": 20,
"currentCount": 21,
"resetIn": 42,
"message": "Please wait before uploading more attachments"
}{
"error": "Attachment not found",
"message": "Attachment not found"
}Messages
Upload an attachment to R2 storage (tiered auth)
Upload a single message attachment to R2 storage. Accepts authenticated agent uploads or unauthenticated webchat uploads gated by a valid webchatConfigId. Returns the storage key plus content metadata for inclusion in a subsequent send-message call.
POST
/
api
/
messages
/
upload-attachment
Upload an attachment to R2 storage (tiered auth)
curl --request POST \
--url https://your-instance.example.com/api/messages/upload-attachment \
--header 'Content-Type: multipart/form-data' \
--form file='@example-file' \
--form webchatConfigId=64a1b2c3d4e5f60012345678import requests
url = "https://your-instance.example.com/api/messages/upload-attachment"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "webchatConfigId": "64a1b2c3d4e5f60012345678" }
response = requests.post(url, data=payload, files=files)
print(response.text)const form = new FormData();
form.append('file', '<binary: receipt.png>');
form.append('webchatConfigId', '64a1b2c3d4e5f60012345678');
const options = {method: 'POST'};
options.body = form;
fetch('https://your-instance.example.com/api/messages/upload-attachment', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://your-instance.example.com/api/messages/upload-attachment",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<binary: receipt.png>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webchatConfigId\"\r\n\r\n64a1b2c3d4e5f60012345678\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://your-instance.example.com/api/messages/upload-attachment"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<binary: receipt.png>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webchatConfigId\"\r\n\r\n64a1b2c3d4e5f60012345678\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://your-instance.example.com/api/messages/upload-attachment")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<binary: receipt.png>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webchatConfigId\"\r\n\r\n64a1b2c3d4e5f60012345678\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://your-instance.example.com/api/messages/upload-attachment")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<binary: receipt.png>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webchatConfigId\"\r\n\r\n64a1b2c3d4e5f60012345678\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"success": true,
"attachment": {
"storageKey": "messages/65a0e0e0e0e0e0e0e0e0e0e0/msg_67b0/photo.jpg",
"filename": "photo.jpg",
"contentType": "image/jpeg",
"size": 184221
}
}{
"error": "Attachment not found",
"message": "Attachment not found"
}{
"error": "Attachment not found",
"message": "Attachment not found"
}{
"error": "Too many requests",
"limit": 20,
"currentCount": 21,
"resetIn": 42,
"message": "Please wait before uploading more attachments"
}{
"error": "Attachment not found",
"message": "Attachment not found"
}Body
multipart/form-data
Multipart form. Send the file as a file part; for unauthenticated webchat uploads also include webchatConfigId. Example with curl: curl -F "file=@receipt.png" -H "Authorization: Bearer $TOKEN" /api/messages/upload-attachment.
⌘I