POST /messages envia um tipo de mensagem por chamada. O tipo é escolhido pelo campo presente no corpo (text, image, video, audio, document, location, contact, poll ou reaction).
O objeto Message
| Campo | Tipo | Descrição |
|---|---|---|
id |
string | Id com prefixo msg_ |
number_id |
string | Número que enviou ou recebeu |
direction |
string | in (recebida) ou out (enviada) |
chat |
object | { type: "contact" | "group", id, phone, name } |
from_phone |
string | Telefone de quem mandou |
type |
string | text, image, video, audio, document, location, contact, poll, reaction, sticker ou unknown |
text |
string | null | Texto ou legenda |
media |
object | null | { id, url, mime_type, filename, size }. A url é assinada e vale 1 hora |
location |
object | null | { latitude, longitude, name, address } |
reply_to |
string | null | Id da mensagem respondida |
status |
string | queued, sent, delivered, read, failed ou received |
error |
object | null | Motivo da falha quando status é failed |
sent_at |
string | null | Quando saiu para o WhatsApp |
created_at |
string | Data de criação |
{
"id": "msg_3n9x0a7q",
"number_id": "num_8f2k1c9d",
"direction": "out",
"chat": { "type": "contact", "id": "ctc_1b6m2p4r", "phone": "5531999999999", "name": "Ana" },
"from_phone": "5531988887777",
"type": "text",
"text": "Oi! Seu pedido saiu para entrega.",
"media": null,
"location": null,
"reply_to": null,
"status": "delivered",
"error": null,
"sent_at": "2026-12-04T15:02:12Z",
"created_at": "2026-12-04T15:02:11Z"
}Enviar texto
POST /messages
| Campo | Tipo | |
|---|---|---|
to |
string | Obrigatório. Telefone (5531999999999) ou id de grupo (grp_...) |
text |
string | Texto da mensagem |
from |
string | Id do número que envia. Opcional com um número só na conta |
reply_to |
string | Id da mensagem a responder (msg_...) |
delay_ms |
integer | 0 a 10000. Mostra “digitando…” antes de enviar |
Cabeçalho opcional Idempotency-Key: repetir a chamada com a mesma chave em 24 horas não envia de novo.
curl -X POST "https://api.avisa.dev/v1/messages" \
-H "Authorization: Bearer $AVISA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: pedido-4821" \
-d '{
"to": "5531999999999",
"text": "Oi! Seu pedido saiu para entrega.",
"delay_ms": 1200
}'const res = await fetch('https://api.avisa.dev/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': 'pedido-4821',
},
body: JSON.stringify({
"to": "5531999999999",
"text": "Oi! Seu pedido saiu para entrega.",
"delay_ms": 1200
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.post(
"https://api.avisa.dev/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
"Idempotency-Key": "pedido-4821",
},
json={
"to": "5531999999999",
"text": "Oi! Seu pedido saiu para entrega.",
"delay_ms": 1200,
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
'Content-Type: application/json',
'Idempotency-Key: pedido-4821',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '5531999999999',
'text' => 'Oi! Seu pedido saiu para entrega.',
'delay_ms' => 1200,
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);{
"id": "msg_3n9x0a7q",
"number_id": "num_8f2k1c9d",
"direction": "out",
"chat": { "type": "contact", "id": "ctc_1b6m2p4r", "phone": "5531999999999", "name": null },
"from_phone": "5531988887777",
"type": "text",
"text": "Oi! Seu pedido saiu para entrega.",
"media": null,
"location": null,
"reply_to": null,
"status": "queued",
"error": null,
"sent_at": null,
"created_at": "2026-12-04T15:02:11Z"
}Enviar imagem
POST /messages com image: { url, caption? }. A url precisa ser pública (HTTPS).
curl -X POST "https://api.avisa.dev/v1/messages" \
-H "Authorization: Bearer $AVISA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "5531999999999",
"image": {
"url": "https://exemplo.com/cardapio.jpg",
"caption": "Cardápio de hoje"
}
}'const res = await fetch('https://api.avisa.dev/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"to": "5531999999999",
"image": {
"url": "https://exemplo.com/cardapio.jpg",
"caption": "Cardápio de hoje"
}
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.post(
"https://api.avisa.dev/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
json={
"to": "5531999999999",
"image": {
"url": "https://exemplo.com/cardapio.jpg",
"caption": "Cardápio de hoje",
},
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '5531999999999',
'image' => [
'url' => 'https://exemplo.com/cardapio.jpg',
'caption' => 'Cardápio de hoje',
],
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Enviar vídeo
POST /messages com video: { url, caption? }.
curl -X POST "https://api.avisa.dev/v1/messages" \
-H "Authorization: Bearer $AVISA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "5531999999999",
"video": {
"url": "https://exemplo.com/tour.mp4",
"caption": "Tour pela loja"
}
}'const res = await fetch('https://api.avisa.dev/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"to": "5531999999999",
"video": {
"url": "https://exemplo.com/tour.mp4",
"caption": "Tour pela loja"
}
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.post(
"https://api.avisa.dev/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
json={
"to": "5531999999999",
"video": {
"url": "https://exemplo.com/tour.mp4",
"caption": "Tour pela loja",
},
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '5531999999999',
'video' => [
'url' => 'https://exemplo.com/tour.mp4',
'caption' => 'Tour pela loja',
],
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Enviar áudio de voz
POST /messages com audio: { url }. O áudio chega como mensagem de voz (PTT), igual a um áudio gravado no celular.
curl -X POST "https://api.avisa.dev/v1/messages" \
-H "Authorization: Bearer $AVISA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "5531999999999",
"audio": {
"url": "https://exemplo.com/recado.ogg"
}
}'const res = await fetch('https://api.avisa.dev/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"to": "5531999999999",
"audio": {
"url": "https://exemplo.com/recado.ogg"
}
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.post(
"https://api.avisa.dev/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
json={
"to": "5531999999999",
"audio": {
"url": "https://exemplo.com/recado.ogg",
},
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '5531999999999',
'audio' => [
'url' => 'https://exemplo.com/recado.ogg',
],
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Enviar documento
POST /messages com document: { url, filename?, caption? }.
curl -X POST "https://api.avisa.dev/v1/messages" \
-H "Authorization: Bearer $AVISA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "5531999999999",
"document": {
"url": "https://exemplo.com/nota-4821.pdf",
"filename": "nota-4821.pdf",
"caption": "Sua nota fiscal"
}
}'const res = await fetch('https://api.avisa.dev/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"to": "5531999999999",
"document": {
"url": "https://exemplo.com/nota-4821.pdf",
"filename": "nota-4821.pdf",
"caption": "Sua nota fiscal"
}
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.post(
"https://api.avisa.dev/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
json={
"to": "5531999999999",
"document": {
"url": "https://exemplo.com/nota-4821.pdf",
"filename": "nota-4821.pdf",
"caption": "Sua nota fiscal",
},
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '5531999999999',
'document' => [
'url' => 'https://exemplo.com/nota-4821.pdf',
'filename' => 'nota-4821.pdf',
'caption' => 'Sua nota fiscal',
],
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Enviar localização
POST /messages com location: { latitude, longitude, name?, address? }.
curl -X POST "https://api.avisa.dev/v1/messages" \
-H "Authorization: Bearer $AVISA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "5531999999999",
"location": {
"latitude": -19.9245,
"longitude": -43.9352,
"name": "Loja Centro",
"address": "Av. Afonso Pena, 1000, Belo Horizonte"
}
}'const res = await fetch('https://api.avisa.dev/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"to": "5531999999999",
"location": {
"latitude": -19.9245,
"longitude": -43.9352,
"name": "Loja Centro",
"address": "Av. Afonso Pena, 1000, Belo Horizonte"
}
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.post(
"https://api.avisa.dev/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
json={
"to": "5531999999999",
"location": {
"latitude": -19.9245,
"longitude": -43.9352,
"name": "Loja Centro",
"address": "Av. Afonso Pena, 1000, Belo Horizonte",
},
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '5531999999999',
'location' => [
'latitude' => -19.9245,
'longitude' => -43.9352,
'name' => 'Loja Centro',
'address' => 'Av. Afonso Pena, 1000, Belo Horizonte',
],
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Enviar contato
POST /messages com contact: { name, phone }. Chega como cartão de contato.
curl -X POST "https://api.avisa.dev/v1/messages" \
-H "Authorization: Bearer $AVISA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "5531999999999",
"contact": {
"name": "Ana (suporte)",
"phone": "5531977776666"
}
}'const res = await fetch('https://api.avisa.dev/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"to": "5531999999999",
"contact": {
"name": "Ana (suporte)",
"phone": "5531977776666"
}
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.post(
"https://api.avisa.dev/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
json={
"to": "5531999999999",
"contact": {
"name": "Ana (suporte)",
"phone": "5531977776666",
},
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '5531999999999',
'contact' => [
'name' => 'Ana (suporte)',
'phone' => '5531977776666',
],
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Enviar enquete
POST /messages com poll: { question, options, multiple? }. multiple: true permite marcar mais de uma opção.
curl -X POST "https://api.avisa.dev/v1/messages" \
-H "Authorization: Bearer $AVISA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "grp_5t7y9u1i",
"poll": {
"question": "Qual horário fica melhor?",
"options": [
"9h",
"14h",
"18h"
],
"multiple": false
}
}'const res = await fetch('https://api.avisa.dev/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"to": "grp_5t7y9u1i",
"poll": {
"question": "Qual horário fica melhor?",
"options": [
"9h",
"14h",
"18h"
],
"multiple": false
}
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.post(
"https://api.avisa.dev/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
json={
"to": "grp_5t7y9u1i",
"poll": {
"question": "Qual horário fica melhor?",
"options": ["9h", "14h", "18h"],
"multiple": False,
},
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => 'grp_5t7y9u1i',
'poll' => [
'question' => 'Qual horário fica melhor?',
'options' => ['9h', '14h', '18h'],
'multiple' => false,
],
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Reagir a uma mensagem
POST /messages com reaction: { message_id, emoji }.
curl -X POST "https://api.avisa.dev/v1/messages" \
-H "Authorization: Bearer $AVISA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "5531999999999",
"reaction": {
"message_id": "msg_3n9x0a7q",
"emoji": "👍"
}
}'const res = await fetch('https://api.avisa.dev/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"to": "5531999999999",
"reaction": {
"message_id": "msg_3n9x0a7q",
"emoji": "👍"
}
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.post(
"https://api.avisa.dev/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
json={
"to": "5531999999999",
"reaction": {
"message_id": "msg_3n9x0a7q",
"emoji": "👍",
},
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => '5531999999999',
'reaction' => [
'message_id' => 'msg_3n9x0a7q',
'emoji' => '👍',
],
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Listar mensagens
GET /messages
Histórico de mensagens enviadas e recebidas, das mais novas para as mais antigas, com busca no texto. Paginado por cursor.
| Parâmetro | Descrição |
|---|---|
number_id |
Só mensagens deste número |
contact |
Só a conversa com este telefone |
direction |
in ou out |
status |
queued, sent, delivered, read, failed ou received |
q |
Busca no texto |
since / until |
Intervalo de datas (ISO 8601) |
limit / cursor |
Paginação |
curl -X GET "https://api.avisa.dev/v1/messages?contact=5531999999999&q=pedido&limit=20" \
-H "Authorization: Bearer $AVISA_API_KEY"const res = await fetch('https://api.avisa.dev/v1/messages?contact=5531999999999&q=pedido&limit=20', {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.get(
"https://api.avisa.dev/v1/messages?contact=5531999999999&q=pedido&limit=20",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages?contact=5531999999999&q=pedido&limit=20');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
],
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);{
"data": [
{ "id": "msg_9k2j4h6g", "direction": "in", "type": "text", "text": "Cadê meu pedido?", "status": "received", "chat": { "type": "contact", "id": "ctc_1b6m2p4r", "phone": "5531999999999", "name": "Ana" }, "created_at": "2026-12-04T15:10:40Z" }
],
"next_cursor": null
}Obter mensagem
GET /messages/{id}
curl -X GET "https://api.avisa.dev/v1/messages/msg_3n9x0a7q" \
-H "Authorization: Bearer $AVISA_API_KEY"const res = await fetch('https://api.avisa.dev/v1/messages/msg_3n9x0a7q', {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.get(
"https://api.avisa.dev/v1/messages/msg_3n9x0a7q",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages/msg_3n9x0a7q');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
],
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Marcar como lida
POST /messages/{id}/read
Marca uma mensagem recebida como lida no WhatsApp (os dois tracinhos azuis).
curl -X POST "https://api.avisa.dev/v1/messages/msg_9k2j4h6g/read" \
-H "Authorization: Bearer $AVISA_API_KEY"const res = await fetch('https://api.avisa.dev/v1/messages/msg_9k2j4h6g/read', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AVISA_API_KEY}`,
},
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);import os
import requests
res = requests.post(
"https://api.avisa.dev/v1/messages/msg_9k2j4h6g/read",
headers={
"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}",
},
)
res.raise_for_status()
data = res.json()<?php
$ch = curl_init('https://api.avisa.dev/v1/messages/msg_9k2j4h6g/read');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('AVISA_API_KEY'),
],
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);Baixar mídia
GET /media/{id}
Devolve o arquivo de uma mídia (med_...) com autenticação. Use quando a media.url assinada da mensagem já tiver expirado (ela vale 1 hora).
curl "https://api.avisa.dev/v1/media/med_2w4e6r8t" \
-H "Authorization: Bearer $AVISA_API_KEY" \
-o arquivo.jpgimport { writeFile } from 'node:fs/promises';
const res = await fetch('https://api.avisa.dev/v1/media/med_2w4e6r8t', {
headers: { Authorization: `Bearer ${process.env.AVISA_API_KEY}` },
});
if (!res.ok) throw new Error((await res.json()).error.message);
await writeFile('arquivo.jpg', Buffer.from(await res.arrayBuffer()));import os
import requests
res = requests.get(
"https://api.avisa.dev/v1/media/med_2w4e6r8t",
headers={"Authorization": f"Bearer {os.environ['AVISA_API_KEY']}"},
)
res.raise_for_status()
with open("arquivo.jpg", "wb") as f:
f.write(res.content)<?php
$ch = curl_init('https://api.avisa.dev/v1/media/med_2w4e6r8t');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('AVISA_API_KEY')],
]);
file_put_contents('arquivo.jpg', curl_exec($ch));
curl_close($ch);