Building
Files and media
# Files and media
Photos, videos, voice notes and audio files go by a link, or on WhatsApp as a file uploaded first.
## By link
Give an https link in `url`. It has to open without signing in. Instagram takes files only this way.
```javascript Node.js
import { Airbox } from "@airboxhq/api";
const client = new Airbox(process.env.AIRBOX_API_KEY);
const { data, error } = await client.messages.sendImage({
to: "+77011234567",
url: "https://shop.example.kz/orders/1042.jpg",
caption: "Your order #1042 is packed",
channel: "whatsapp",
}, { idempotencyKey: "order-1042-photo" });
if (error) {
throw new Error(`${error.code}: ${error.message} (${error.requestId})`);
}
console.log(data);
```
```php PHP
<?php
require __DIR__.'/vendor/autoload.php';
$client = new Airbox\Client(getenv('AIRBOX_API_KEY'));
$data = $client->messages->sendImage([
'to' => '+77011234567',
'url' => 'https://shop.example.kz/orders/1042.jpg',
'caption' => 'Your order #1042 is packed',
'channel' => 'whatsapp',
], ['idempotency_key' => 'order-1042-photo']);
print_r($data);
```
```python Python
import os
from airboxhq import Airbox
client = Airbox(api_key=os.environ["AIRBOX_API_KEY"])
data = client.messages.send_image(
to="+77011234567",
url="https://shop.example.kz/orders/1042.jpg",
caption="Your order #1042 is packed",
channel="whatsapp",
idempotency_key="order-1042-photo",
)
print(data)
```
```go Go
package main
import (
"context"
"fmt"
"os"
"github.com/airboxhq/airbox-go"
)
func main() {
client := airbox.NewClient(os.Getenv("AIRBOX_API_KEY"))
data, err := client.Messages.SendImage(context.Background(), airbox.SendImageParams{
To: "+77011234567",
URL: "https://shop.example.kz/orders/1042.jpg",
Caption: "Your order #1042 is packed",
Channel: "whatsapp",
}, airbox.WithIdempotencyKey("order-1042-photo"))
if err != nil {
panic(err)
}
fmt.Println(data)
}
```
```csharp .NET
using Airbox;
var client = new AirboxClient(Environment.GetEnvironmentVariable("AIRBOX_API_KEY"));
var data = await client.Messages.SendImageAsync(
new SendImageParams
{
To = "+77011234567",
Url = "https://shop.example.kz/orders/1042.jpg",
Caption = "Your order #1042 is packed",
Channel = "whatsapp",
},
new RequestOptions { IdempotencyKey = "order-1042-photo" });
Console.WriteLine(data);
```
```rust Rust
use airboxhq::Airbox;
use airboxhq::models::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Airbox::new(std::env::var("AIRBOX_API_KEY")?);
let data = client
.messages()
.send_image(SendImage {
to: "+77011234567".into(),
url: Some("https://shop.example.kz/orders/1042.jpg".into()),
caption: Some("Your order #1042 is packed".into()),
channel: Some("whatsapp".into()),
..Default::default()
})
.idempotency_key("order-1042-photo")
.await?;
println!("{data:#?}");
Ok(())
}
```
```bash cURL
curl -X POST https://crm.fintelligence.kz/api/v1/messages \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Idempotency-Key: order-1042-photo" \
-H "Content-Type: application/json" \
-d '{
"to": "+77011234567",
"channel": "whatsapp",
"type": "image",
"image": {
"url": "https://shop.example.kz/orders/1042.jpg",
"caption": "Your order #1042 is packed"
}
}'
```
## By upload
On WhatsApp, upload the file with `POST /v1/media`, then send its `id` as `media_id`. An uploaded file can be sent for 30 days.
```javascript Node.js
import { readFile } from "node:fs/promises";
import { Airbox } from "@airboxhq/api";
const client = new Airbox(process.env.AIRBOX_API_KEY);
const { data, error } = await client.media.upload(await readFile("voice.ogg"), {
filename: "voice.ogg",
contentType: "audio/ogg",
});
if (error) {
throw new Error(`${error.code}: ${error.message} (${error.requestId})`);
}
console.log(data);
```
```php PHP
<?php
require __DIR__.'/vendor/autoload.php';
$client = new Airbox\Client(getenv('AIRBOX_API_KEY'));
$data = $client->media->upload('voice.ogg');
print_r($data);
```
```python Python
import os
from airboxhq import Airbox
client = Airbox(api_key=os.environ["AIRBOX_API_KEY"])
data = client.media.upload("voice.ogg")
print(data)
```
```go Go
package main
import (
"context"
"fmt"
"os"
"github.com/airboxhq/airbox-go"
)
func main() {
client := airbox.NewClient(os.Getenv("AIRBOX_API_KEY"))
file, err := os.Open("voice.ogg")
if err != nil {
panic(err)
}
defer file.Close()
data, err := client.Media.Upload(context.Background(), file, airbox.UploadParams{
Filename: "voice.ogg",
ContentType: "audio/ogg",
})
if err != nil {
panic(err)
}
fmt.Println(data)
}
```
```csharp .NET
using Airbox;
var client = new AirboxClient(Environment.GetEnvironmentVariable("AIRBOX_API_KEY"));
await using var file = File.OpenRead("voice.ogg");
var data = await client.Media.UploadAsync(
file,
new UploadParams
{
FileName = "voice.ogg",
ContentType = "audio/ogg",
});
Console.WriteLine(data);
```
```rust Rust
use airboxhq::Airbox;
use airboxhq::models::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Airbox::new(std::env::var("AIRBOX_API_KEY")?);
let data = client
.media()
.upload(
std::fs::read("voice.ogg")?,
Upload {
filename: Some("voice.ogg".into()),
content_type: Some("audio/ogg".into()),
..Default::default()
},
)
.await?;
println!("{data:#?}");
Ok(())
}
```
```bash cURL
curl -X POST https://crm.fintelligence.kz/api/v1/media \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@voice.ogg" \
-F "channel=whatsapp"
```
## Formats and sizes
| Type | Formats | Up to |
| --- | --- | --- |
| `image` | JPEG, PNG | 5 MB |
| `video` | MP4, 3GP (H.264 and AAC) | 16 MB |
| `audio` | AAC, AMR, MP3, M4A, OGG (Opus, mono) | 16 MB |
| `voice` | OGG with the Opus codec, a link ending in `.ogg` or `.opus` | 16 MB |
A photo or a video takes a `caption` of up to 1,024 characters. On Instagram the caption goes as a message of its own.
## Files customers send
A file in an incoming message comes with its `media_id`, `mime_type` and `expires_at`. Download it with `GET /v1/media/{id}` before then: the channel keeps it 7 days, and we keep no copy.
```javascript Node.js
import { writeFile } from "node:fs/promises";
import { Airbox } from "@airboxhq/api";
const client = new Airbox(process.env.AIRBOX_API_KEY);
const { data, error } = await client.media.download("med_0199c5e2-6a2a-7b41-8e0d-2f1c3a4b5d6f");
if (error) {
throw new Error(`${error.code}: ${error.message} (${error.requestId})`);
}
await writeFile("voice.ogg", data);
```
```php PHP
<?php
require __DIR__.'/vendor/autoload.php';
$client = new Airbox\Client(getenv('AIRBOX_API_KEY'));
$data = $client->media->download('med_0199c5e2-6a2a-7b41-8e0d-2f1c3a4b5d6f');
file_put_contents('voice.ogg', $data);
```
```python Python
import os
from airboxhq import Airbox
client = Airbox(api_key=os.environ["AIRBOX_API_KEY"])
data = client.media.download("med_0199c5e2-6a2a-7b41-8e0d-2f1c3a4b5d6f")
with open("voice.ogg", "wb") as file:
file.write(data)
```
```go Go
package main
import (
"context"
"os"
"github.com/airboxhq/airbox-go"
)
func main() {
client := airbox.NewClient(os.Getenv("AIRBOX_API_KEY"))
data, err := client.Media.Download(context.Background(), "med_0199c5e2-6a2a-7b41-8e0d-2f1c3a4b5d6f")
if err != nil {
panic(err)
}
os.WriteFile("voice.ogg", data, 0o644)
}
```
```csharp .NET
using Airbox;
var client = new AirboxClient(Environment.GetEnvironmentVariable("AIRBOX_API_KEY"));
var data = await client.Media.DownloadAsync("med_0199c5e2-6a2a-7b41-8e0d-2f1c3a4b5d6f");
await File.WriteAllBytesAsync("voice.ogg", data);
```
```rust Rust
use airboxhq::Airbox;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Airbox::new(std::env::var("AIRBOX_API_KEY")?);
let data = client
.media()
.download("med_0199c5e2-6a2a-7b41-8e0d-2f1c3a4b5d6f")
.await?;
std::fs::write("voice.ogg", &data)?;
Ok(())
}
```
```bash cURL
curl -X GET https://crm.fintelligence.kz/api/v1/media/med_0199c5e2-6a2a-7b41-8e0d-2f1c3a4b5d6f \
-H "Authorization: Bearer YOUR_API_KEY" \
--fail-with-body -o voice.ogg
```
Updated 4 December 2026
Photos, videos, voice notes and audio files go by a link, or on WhatsApp as a file uploaded first.
By link
Give an https link in url. It has to open without signing in. Instagram takes files only this way.
import { Airbox } from "@airboxhq/api";
const client = new Airbox(process.env.AIRBOX_API_KEY);
const { data, error } = await client.messages.sendImage({
to: "+77011234567",
url: "https://shop.example.kz/orders/1042.jpg",
caption: "Your order #1042 is packed",
channel: "whatsapp",
}, { idempotencyKey: "order-1042-photo" });
if (error) {
throw new Error(`${error.code}: ${error.message} (${error.requestId})`);
}
console.log(data);
By upload
On WhatsApp, upload the file with POST /v1/media, then send its id as media_id. An uploaded file can be sent for 30 days.
import { readFile } from "node:fs/promises";
import { Airbox } from "@airboxhq/api";
const client = new Airbox(process.env.AIRBOX_API_KEY);
const { data, error } = await client.media.upload(await readFile("voice.ogg"), {
filename: "voice.ogg",
contentType: "audio/ogg",
});
if (error) {
throw new Error(`${error.code}: ${error.message} (${error.requestId})`);
}
console.log(data);
Formats and sizes
| Type | Formats | Up to |
|---|---|---|
image |
JPEG, PNG | 5 MB |
video |
MP4, 3GP (H.264 and AAC) | 16 MB |
audio |
AAC, AMR, MP3, M4A, OGG (Opus, mono) | 16 MB |
voice |
OGG with the Opus codec, a link ending in .ogg or .opus |
16 MB |
A photo or a video takes a caption of up to 1,024 characters. On Instagram the caption goes as a message of its own.
Files customers send
A file in an incoming message comes with its media_id, mime_type and expires_at. Download it with GET /v1/media/{id} before then: the channel keeps it 7 days, and we keep no copy.
import { writeFile } from "node:fs/promises";
import { Airbox } from "@airboxhq/api";
const client = new Airbox(process.env.AIRBOX_API_KEY);
const { data, error } = await client.media.download("med_0199c5e2-6a2a-7b41-8e0d-2f1c3a4b5d6f");
if (error) {
throw new Error(`${error.code}: ${error.message} (${error.requestId})`);
}
await writeFile("voice.ogg", data);