Enviar ou hospedar mídia
curl --request POST \
--url https://api.routa.chat/v1/media \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"source_url": "https://exemplo.com/imagem.png"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({source_url: 'https://exemplo.com/imagem.png'})
};
fetch('https://api.routa.chat/v1/media', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.routa.chat/v1/media"
payload = { "source_url": "https://exemplo.com/imagem.png" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.routa.chat/v1/media",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'source_url' => 'https://exemplo.com/imagem.png'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://api.routa.chat/v1/media"
payload := strings.NewReader("{\n \"source_url\": \"https://exemplo.com/imagem.png\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "med_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
"content_type": "image/jpeg",
"status": "pending",
"url": "<string>"
}{
"error": {
"type": "invalid_request_error",
"code": "channel_inactive",
"message": "Channel chan_01J8... is not active and cannot send messages.",
"request_id": "req_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
"param": "<string>",
"doc_url": "<string>",
"details": {}
}
}{
"error": {
"type": "invalid_request_error",
"code": "channel_inactive",
"message": "Channel chan_01J8... is not active and cannot send messages.",
"request_id": "req_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
"param": "<string>",
"doc_url": "<string>",
"details": {}
}
}{
"error": {
"type": "invalid_request_error",
"code": "channel_inactive",
"message": "Channel chan_01J8... is not active and cannot send messages.",
"request_id": "req_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
"param": "<string>",
"doc_url": "<string>",
"details": {}
}
}{
"error": {
"type": "invalid_request_error",
"code": "channel_inactive",
"message": "Channel chan_01J8... is not active and cannot send messages.",
"request_id": "req_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
"param": "<string>",
"doc_url": "<string>",
"details": {}
}
}Mídia
Enviar ou hospedar mídia
Armazena um arquivo de mídia sob custódia da Routa. Há duas formas, escolhidas pelo Content-Type:
- Bytes: envie o arquivo no corpo, com o
Content-Typedo arquivo. - URL: envie
application/jsoncom{ "source_url": "https://..." }e a Routa baixa o arquivo. A URL precisa ser pública.
Os tipos e os tamanhos aceitos seguem os limites do WhatsApp. Veja Mídia.
POST
/
v1
/
media
Enviar ou hospedar mídia
curl --request POST \
--url https://api.routa.chat/v1/media \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"source_url": "https://exemplo.com/imagem.png"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({source_url: 'https://exemplo.com/imagem.png'})
};
fetch('https://api.routa.chat/v1/media', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.routa.chat/v1/media"
payload = { "source_url": "https://exemplo.com/imagem.png" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.routa.chat/v1/media",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'source_url' => 'https://exemplo.com/imagem.png'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://api.routa.chat/v1/media"
payload := strings.NewReader("{\n \"source_url\": \"https://exemplo.com/imagem.png\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "med_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
"content_type": "image/jpeg",
"status": "pending",
"url": "<string>"
}{
"error": {
"type": "invalid_request_error",
"code": "channel_inactive",
"message": "Channel chan_01J8... is not active and cannot send messages.",
"request_id": "req_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
"param": "<string>",
"doc_url": "<string>",
"details": {}
}
}{
"error": {
"type": "invalid_request_error",
"code": "channel_inactive",
"message": "Channel chan_01J8... is not active and cannot send messages.",
"request_id": "req_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
"param": "<string>",
"doc_url": "<string>",
"details": {}
}
}{
"error": {
"type": "invalid_request_error",
"code": "channel_inactive",
"message": "Channel chan_01J8... is not active and cannot send messages.",
"request_id": "req_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
"param": "<string>",
"doc_url": "<string>",
"details": {}
}
}{
"error": {
"type": "invalid_request_error",
"code": "channel_inactive",
"message": "Channel chan_01J8... is not active and cannot send messages.",
"request_id": "req_01J8ZK9M3Q7XABCDEFGHJKMNPQ",
"param": "<string>",
"doc_url": "<string>",
"details": {}
}
}Authorizations
Chave de API do projeto, no formato rt_live_... ou rt_test_..., enviada como Authorization: Bearer <chave>.
Body
application/jsonapplication/octet-stream
URL pública do arquivo que a Routa deve baixar.
Example:
"https://exemplo.com/imagem.png"
Response
Recurso criado
Identificador da mídia.
Example:
"med_01J8ZK9M3Q7XABCDEFGHJKMNPQ"
Tipo MIME do arquivo.
Example:
"image/jpeg"
Estado: pending, ready ou unavailable.
Available options:
pending, ready, unavailable URL assinada com validade de 15 minutos. Presente apenas quando status é ready.