Media Files
JavaScript multipart/form-data Example To Create A Media File:
const file = document.querySelector("input[type=file]").files[0];
const data = new FormData();
data.append('file_encoded', file);
fetch('/api/v1/media/', {
'method': 'POST',
'headers': {
'Authorization': 'Token YOUR_TOKEN_HERE',
},
'body': data
}).then(response => {
return response.json();
}).then(data => {
console.log(data.file);
}).catch((error) => {
console.error('Error:', error);
});Above POST request will produce a valid binary file upload HTTP request similar to:
After API will return with specified JSON data, line console.log(data.file); will print a direct URL to uploaded media file.
Create a new media file
Use this endpoint to upload a new media file before you enter it into a new message as an attachment.
A user token, sent as Token <token>. Create a user in the admin panel (group App integration) and get its token from POST /api/v1/auth/token/. The channel API key (D360-Api-Key) is not supported.
Encoded in Base64.
An authorization-free link to your media file. This link will contain query params: mime_type_type and mime_type_subtype that, when combined together, determine for you a content type of retrieved media file: {mime_type_type}/{mime_type_subtype}. For example: mime_type_type=image&mime_type_subtype=jpeg means Content-Type: image/jpeg. This information is not needed for HTTP client that will ignore file type (for example most of web browsers during file download), but it will be crucial for others (for example web browsers during file display or WhatsApp displaying outgoing message media to end users)
POST /api/v1/media/ HTTP/1.1
Host: your-stack.inbox.getchat.360dialog.io/
Authorization: Token YOUR_TOKEN
Content-Type: multipart/form-data
Accept: */*
Content-Length: 23
{
"file_encoded": "text"
}{
"file": "https://example.com",
"id": "123e4567-e89b-12d3-a456-426614174000"
}Retrieve binary raw media file
Used in media messages and for display.
Owned media (uploaded via this Inbox, identified by a UUID) is served as a 302 redirect to a short-lived signed URL on Google Cloud Storage, so the bucket can stay private and bytes never flow through the Inbox pod.
Inbound media hosted by WABA (numeric IDs) is proxied through WABA-Stack as before.
A user token, sent as Token <token>. Create a user in the admin panel (group App integration) and get its token from POST /api/v1/auth/token/. The channel API key (D360-Api-Key) is not supported.
A UUID string identifying this media file.
mime_type_type and mime_type_subtype that, when combined together, determine for you a content type of retrieved media file - {mime_type_type}/{mime_type_subtype}. For example mime_type_type=image&mime_type_subtype=jpeg means Content-Type image/jpeg. This information is not needed for HTTP client that will ignore file type (for example most of web browsers during file download) but it will be crucial for others (for example web browsers during file display or WhatsApp displaying outgoing message media to end users)
mime_type_type and mime_type_subtype that, when combined together, determine for you a content type of retrieved media file: {mime_type_type}/{mime_type_subtype}. For example mime_type_type=image&mime_type_subtype=jpeg means Content-Type image/jpeg. This information is not needed for HTTP client that will ignore file type (for example most of web browsers during file download) but it will be crucial for others (for example web browsers during file display or WhatsApp displaying outgoing message media to end users)
Owned media (UUID). Redirects to a short-lived signed URL on Google Cloud Storage; clients should follow the redirect to download the bytes.
There is no such file, or the file was deleted (e.g. expired at WhatsApp).
Media downloads are temporarily rate limited upstream. Retry after the number of seconds in the Retry-After header.
Media file is temporarily unavailable due to an upstream error. Retry later.
GET /api/v1/media/{id}/ HTTP/1.1
Host: your-stack.inbox.getchat.360dialog.io/
Authorization: Token YOUR_TOKEN
Accept: */*
binaryLast updated
Was this helpful?