Mengunggah Media (Upload)
Endpoint ini digunakan untuk mengunggah berkas media (gambar, audio, video, dokumen) ke server Meta. Media yang berhasil diunggah akan mendapatkan id unik (Media ID) yang dapat digunakan saat mengirim pesan media ke pelanggan.
🛜 Endpoint
POST /v1/media
📋 Content-Type
multipart/form-data
📦 Form Fields
| Field | Tipe | Wajib | Keterangan |
|---|---|---|---|
file |
File | Ya | Berkas biner media yang akan diunggah |
type |
String | Ya | Tipe konten MIME dari berkas (contoh: image/png, video/mp4, application/pdf) |
📏 Jenis Media & Batasan Ukuran
WhatsApp membatasi jenis dan ukuran berkas media yang dapat diunggah:
| Tipe Media | Ekstensi | Ukuran Maks |
|---|---|---|
| Gambar | .jpg, .jpeg, .png |
5 MB |
| Audio | .aac, .mp4, .amr, .mpeg, .opus, .ogg |
16 MB |
| Video | .mp4, .3gp |
16 MB |
| Dokumen | .txt, .xls, .xlsx, .doc, .docx, .ppt, .pptx, .pdf |
100 MB |
Catatan: Batasan di atas mengikuti kebijakan resmi WhatsApp Business Platform. File yang melebihi batas akan ditolak dengan error
413.
🚦 Contoh cURL Request
curl -X POST https://api.kirem.co/v1/media \
-H "Authorization: Bearer kirem_live_xxx" \
-F "file=@/path/to/product-image.png" \
-F "type=image/png"
🚦 Contoh Kode (Node.js)
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const form = new FormData();
form.append('file', fs.createReadStream('/path/to/product-image.png'));
form.append('type', 'image/png');
axios.post('https://api.kirem.co/v1/media', form, {
headers: {
...form.getHeaders(),
'Authorization': 'Bearer kirem_live_xxx'
}
}).then(res => console.log(res.data));
🚦 Contoh Kode (Go)
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var buf bytes.Buffer
w := multipart.NewWriter(&buf)
w.WriteField("type", "image/png")
fw, _ := w.CreateFormFile("file", "product-image.png")
file, _ := os.Open("/path/to/product-image.png")
io.Copy(fw, file)
file.Close()
w.Close()
req, _ := http.NewRequest("POST", "https://api.kirem.co/v1/media", &buf)
req.Header.Set("Authorization", "Bearer kirem_live_xxx")
req.Header.Set("Content-Type", w.FormDataContentType())
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
fmt.Println("Status:", resp.Status)
}
🚦 Contoh Kode (PHP)
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.kirem.co/v1/media');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer kirem_live_xxx'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'file' => new CURLFile('/path/to/product-image.png'),
'type' => 'image/png'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
✅ Respons Sukses (200 OK)
{
"status": 200,
"message": "Media uploaded successfully",
"data": {
"id": "18471948194819"
}
}
| Field | Keterangan |
|---|---|
data.id |
Media ID — simpan nilai ini untuk digunakan saat mengirim pesan media, mengunduh, atau menghapus media |
⚠️ Error Umum
| Kode | Pesan Error | Penyebab |
|---|---|---|
| 400 | file is required |
Field file tidak disertakan dalam request |
| 400 | type is required |
Field type tidak disertakan dalam request |
| 413 | file too large |
Ukuran file melebihi batas maksimal yang diizinkan WhatsApp |
| 415 | unsupported media type |
Format atau tipe file tidak didukung oleh WhatsApp |