> For the complete documentation index, see [llms.txt](https://docs.360dialog.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.360dialog.com/docs/inbox/inbox-api/api-ref/media-files.md).

# Media Files

JavaScript multipart/form-data Example To Create A Media File:

```javascript
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:

```http
-----------------------------332889473834598984683101881237
Content-Disposition: form-data; name="file_encoded"; filename="img.jpg"
Content-Type: image/jpeg

<binary data here>
```

After API will return with specified JSON data, line `console.log(data.file);` will print a direct URL to uploaded media file.

## POST /api/v1/media/

> 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.

````json
{"openapi":"3.0.3","info":{"title":"360dialog Inbox API","version":"1.28.0"},"tags":[{"name":"Media Files","description":"\nJavaScript multipart/form-data Example To Create A Media File:\n```javascript\nconst file = document.querySelector(\"input[type=file]\").files[0];\n\nconst data = new FormData();\ndata.append('file_encoded', file);\n\nfetch('/api/v1/media/', {\n'method': 'POST',\n'headers': {\n  'Authorization': 'Token YOUR_TOKEN_HERE',\n},\n'body': data\n}).then(response => {\n  return response.json();\n}).then(data => {\n  console.log(data.file);\n}).catch((error) => {\n  console.error('Error:', error);\n});\n```\n\nAbove POST request will produce a valid binary file upload HTTP request similar to:\n\n```http\n-----------------------------332889473834598984683101881237\nContent-Disposition: form-data; name=\"file_encoded\"; filename=\"img.jpg\"\nContent-Type: image/jpeg\n\n<binary data here>\n```\n\nAfter API will return with specified JSON data, line `console.log(data.file);` will print a direct URL\nto uploaded media file.\n                "}],"servers":[{"url":"https://{YOUR_STACK_NAME}.inbox.getchat.360dialog.io/","description":"Your Inbox address. Open the Inbox from the 360dialog Hub to see it.","variables":{"YOUR_STACK_NAME":{"default":"your-stack","description":"The first part of your Inbox address"}}}],"security":[{"tokenAuth":[]}],"components":{"securitySchemes":{"tokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"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."}},"schemas":{"MediaCreateRequest":{"type":"object","properties":{"file_encoded":{"type":"string","description":"Encoded in [Base64](https://en.wikipedia.org/wiki/Base64)."}},"required":["file_encoded"]},"CreateMedia":{"type":"object","properties":{"file_encoded":{"type":"string","format":"uri","writeOnly":true},"file":{"type":"string","format":"uri","readOnly":true,"description":"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)"},"id":{"type":"string","format":"uuid","readOnly":true}},"required":["file","file_encoded","id"]}}},"paths":{"/api/v1/media/":{"post":{"operationId":"createMediaFile","description":"Create a new media file\n\nUse this endpoint to upload a new media file **before** you enter it into a new message as an attachment.","tags":["Media Files"],"requestBody":{"content":{"multipart/form-data":{"schema":{"$ref":"#/components/schemas/MediaCreateRequest"}}},"required":true},"responses":{"201":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateMedia"}}},"description":""}}}}}}
````

## GET /api/v1/media/{id}/

> Retrieve binary raw media file\
> \
> Used in media messages and for display.\
> \
> \- Owned media (uploaded via this Inbox, identified by a UUID) is\
> &#x20; served as a 302 redirect to a short-lived signed URL on Google\
> &#x20; Cloud Storage, so the bucket can stay private and bytes never\
> &#x20; flow through the Inbox pod.\
> \- Inbound media hosted by WABA (numeric IDs) is proxied through\
> &#x20; WABA-Stack as before.

````json
{"openapi":"3.0.3","info":{"title":"360dialog Inbox API","version":"1.28.0"},"tags":[{"name":"Media Files","description":"\nJavaScript multipart/form-data Example To Create A Media File:\n```javascript\nconst file = document.querySelector(\"input[type=file]\").files[0];\n\nconst data = new FormData();\ndata.append('file_encoded', file);\n\nfetch('/api/v1/media/', {\n'method': 'POST',\n'headers': {\n  'Authorization': 'Token YOUR_TOKEN_HERE',\n},\n'body': data\n}).then(response => {\n  return response.json();\n}).then(data => {\n  console.log(data.file);\n}).catch((error) => {\n  console.error('Error:', error);\n});\n```\n\nAbove POST request will produce a valid binary file upload HTTP request similar to:\n\n```http\n-----------------------------332889473834598984683101881237\nContent-Disposition: form-data; name=\"file_encoded\"; filename=\"img.jpg\"\nContent-Type: image/jpeg\n\n<binary data here>\n```\n\nAfter API will return with specified JSON data, line `console.log(data.file);` will print a direct URL\nto uploaded media file.\n                "}],"servers":[{"url":"https://{YOUR_STACK_NAME}.inbox.getchat.360dialog.io/","description":"Your Inbox address. Open the Inbox from the 360dialog Hub to see it.","variables":{"YOUR_STACK_NAME":{"default":"your-stack","description":"The first part of your Inbox address"}}}],"security":[{"tokenAuth":[]}],"components":{"securitySchemes":{"tokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"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."}}},"paths":{"/api/v1/media/{id}/":{"get":{"operationId":"retrieveMediaFile","description":"Retrieve binary raw media file\n\nUsed in media messages and for display.\n\n- Owned media (uploaded via this Inbox, identified by a UUID) is\n  served as a 302 redirect to a short-lived signed URL on Google\n  Cloud Storage, so the bucket can stay private and bytes never\n  flow through the Inbox pod.\n- Inbound media hosted by WABA (numeric IDs) is proxied through\n  WABA-Stack as before.","parameters":[{"in":"path","name":"id","schema":{"type":"string","format":"uuid"},"description":"A UUID string identifying this media file.","required":true},{"in":"query","name":"mime_type_subtype","schema":{"type":"string"},"description":"`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)"},{"in":"query","name":"mime_type_type","schema":{"type":"string"},"description":"`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)"}],"tags":["Media Files"],"responses":{"200":{"content":{"image/jpeg":{"schema":{"type":"string","format":"binary"}},"image/png":{"schema":{"type":"string","format":"binary"}},"image/webp":{"schema":{"type":"string","format":"binary"}},"video/mp4":{"schema":{"type":"string","format":"binary"}},"video/3gpp":{"schema":{"type":"string","format":"binary"}},"audio/aac":{"schema":{"type":"string","format":"binary"}},"audio/mp4":{"schema":{"type":"string","format":"binary"}},"audio/amr":{"schema":{"type":"string","format":"binary"}},"audio/mpeg":{"schema":{"type":"string","format":"binary"}},"audio/ogg; codecs=opus":{"schema":{"type":"string","format":"binary"}}},"description":""},"302":{"description":"Owned media (UUID). Redirects to a short-lived signed URL on Google Cloud Storage; clients should follow the redirect to download the bytes."},"404":{"description":"There is no such file, or the file was deleted (e.g. expired at WhatsApp)."},"429":{"description":"Media downloads are temporarily rate limited upstream. Retry after the number of seconds in the Retry-After header."},"503":{"description":"Media file is temporarily unavailable due to an upstream error. Retry later."}}}}}}
````


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.360dialog.com/docs/inbox/inbox-api/api-ref/media-files.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
