Assets API
The Assets API can be used to manage assets in bulk.
What to know
- Delete assets programmatically via the Assets API
- Encode asset URLs to ensure functional API calls
Necessary permissions
To access assets through the Assets API, you must have the following:
- A Public API Key
- A Space Private Key
See API Keys for more information.
Delete assets
You can delete assets by ID, URL or GraphQL.
By ID
Make the following request, replacing ASSET_ID, PUBLIC_API_KEY, and PRIVATE_API_KEY with your asset ID and your space's public and private key.
By URL
Make the following request, replacing ENCODED_ASSET_URL, PUBLIC_API_KEY, and PRIVATE_API_KEY with your asset's encoded URL and your space's public and private key.
Using GraphQL
Delete assets using GraphQL with the deleteAsset mutation. This approach requires only the asset ID and private API key.
Make the following request, replacing ASSET_ID and YOUR_BUILDER_PRIVATE_KEY with the asset ID and private key:
An example GraphQL mutation:
For more GraphQL mutations and queries, see Admin GraphQL Schema.
Access your asset's URL
To access your asset's URL:
- Visit your Asset Library and right-click on an image
- Select Copy Image Address
You also receive the image URL when using the Upload API.
Note: Your asset URL may not have any parameters attached to it. For example, parameters like ?width=500&height=500 should be removed.
Encode your asset's URL
The asset's URL must be encoded. An encoded URL will look like the following:
Note that the asset URL you retrieve from Builder may already be partially encoded. You can tell by the presence of %2F characters within the URL.
Leave these characters within the URL when encoding.
Encode your URL
To encode your URL, use the encodeURIComponent() built-in JavaScript function.
Note: The asset URL you retrieve from Builder may already be partially encoded. You can tell by the presence of %2F characters within the URL.
Leave these characters within the URL when encoding.
Query assets
Sort assets
Use the following query to sort your assets by a particular key, such as the asset's name.
Query
Response
Filter assets by type
To filter assets by media type (such as images, videos, or specific formats), use the type field. Note that this corresponds to the MIME type of the asset.
Query
Response
Common asset types:
image/jpeg: jpeg images
image/png: png images
image/svg+xml: svg images
image/gif: gif images
image/webp: webp images
video/mp4: mp4 videos
application/pdf: pdf documents
Filter assets by folder
To filter assets by folder, use the folders field with the folder ID. Assets can belong to multiple folders, so folders is an array field.
Query
Response
Filter assets by type and folder
You can combine multiple filters to get more specific results. For example, to get all SVG images from a specific folder:
Query
Response
Using variables for dynamic queries
Query
Available query operators
$eq: equal
$ne: not equal
$in: in array
$nin: not in array
$exists: field exists
$regex: regular expression match
Example with multiple operators:
This query returns jpeg or png images that have "logo" in their name and belong to at least one folder.
What's next
Programmatically upload files with the Upload API or learn more about how to access images with the Image API.