Upload an asset to the media library
/media_library/create
Use this endpoint to add an asset to the Braze media library using either an externally hosted URL (
asset_url) or binary file data sent in the request body (asset_file). This endpoint supports images and ZIP files that contain images.
Prerequisites
To use this endpoint, you’ll need an API key with the media_library.create permission.
Rate limit
We apply the default Braze rate limit of 250,000 requests per hour to this endpoint, as documented in API rate limits.
Request body
When you include asset_url, the endpoint downloads the file from the URL. When you include asset_file, the endpoint uses the binary data in the request body.
Example request body for asset_url:
1
2
3
4
{
"asset_url": "https://cdn.example.com/assets/cat.jpg",
"name": "Cat Graphic"
}
Example request body for asset_file:
1
2
3
4
{
"asset_file": <BINARY FILE DATA>,
"name": "Cat Graphic"
}
The request body includes the following parameters:
| Parameter | Required | Data Type | Description |
|---|---|---|---|
asset_url |
Optional | String | A publicly accessible URL for the asset to be uploaded into Braze. |
asset_file |
Optional | Binary | Binary file data. |
name |
Optional | String | A name to appear in the media library for this asset. |
asset_url and asset_file are mutually exclusive, you must only include one of them in your API request.
Uploaded file names
This section explains how the endpoint assigns names to uploaded files based on whether you include the name parameter.
Single file uploads
| Scenario | Result |
|---|---|
name provided |
The name value is used as the asset name in the media library. |
name excluded |
The original filename from the URL or uploaded file is used. |
ZIP file uploads
| Scenario | Result |
|---|---|
name provided |
The name value is used as a prefix, with an incrementing number appended as a suffix (for example, “My File 1”, “My File 2”, “My File 3”). |
name excluded |
Each file retains its original filename from within the ZIP file. |
Example request
This section includes two example curl requests, one for adding an asset using a URL and another using binary file data.
This request shows an example of adding an asset to the media library using an asset_url.
1
2
3
4
curl -X POST --location 'http://api.dashboard-03.braze.com/media_library/create' \
--header 'Authorization: Bearer YOUR-REST-API-KEY' \
--header 'Content-Type: application/json' \
--data '{"asset_url": "https://cdn.example.com/assets/cat.jpg", "name": "Cat Graphic"}'
This request shows an example of adding an asset to the media library using an asset_file.
1
2
3
4
curl -X POST --location 'http://api.dashboard-03.braze.com/media_library/create' \
--header 'Authorization: Bearer YOUR-REST-API-KEY' \
--header 'Content-Type: application/json' \
--data '{"asset_file":<BINARY FILE DATA>, "name":"Cat Graphic"}'
Error responses
This section lists potential errors and their corresponding messages and descriptions.
Validation errors
Validation errors return a structure like this:
1
2
3
{
"message": (String) Human-readable error description
}
This table lists possible validation errors.
| HTTP Status | Message | Description |
|---|---|---|
| 400 | “Either asset_url or asset_file must be provided.” | No asset parameter was provided in the request. |
| 400 | “Both asset_url and asset_file cannot be provided. Please provide only one.” | Both asset parameters were provided; only one is allowed. |
| 403 | “Media Library Public APIs are not enabled for this company.” | Media library feature is not enabled for this workspace. |
Processing errors
Processing errors return a different response with error codes:
1
2
3
4
5
{
"message": (String) Human-readable error description,
"error_code": (String) error code,
"meta": { }
}
This table lists possible processing errors.
| Error Code | HTTP Status | Description |
|---|---|---|
UNSUPPORTED_FILE_TYPE |
400 | The uploaded file type is not supported. The meta object includes the file_type that was rejected. |
ASSET_SIZE_EXCEEDS_LIMIT |
400 | The file exceeds the maximum allowed size. Images have a 5 MB limit. |
MEDIA_LIBRARY_LIMIT_REACHED |
400 | The workspace has reached its maximum number of assets (200 by default for free trial companies, unlimited otherwise). The meta object includes the current limit. |
ASSET_UPLOAD_FAILED |
400 | The asset failed to upload due to processing issues. |
GENERIC_ERROR |
500 | An unexpected error occurred during upload. The meta object includes the original_error message for debugging. Try again or contact Support. |
Response
There are five status code responses for this endpoint: 200, 400, 403, 429, and 500.
The following JSON shows the expected shape of the response.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"new_assets": [
{
"name": (String) the name of the asset,
"size": (Integer) the byte size of the asset,
"url": (String) the URL to access the asset,
"ext": (String) the file extension (e.g., "png", "jpg", "gif")
}
],
"errors": [
{
"name": (String) the name of the asset,
"size": (Integer) the byte size of the asset,
"ext": (String) the file extension (e.g., "png", "jpg", "gif"),
"error": (String) the error that occurred
}
],
"dashboard_url": (String) the URL to view this asset in the Braze dashboard
}
Edit this page on GitHub