The Assets API can be used to manage assets in bulk.
- Delete assets programmatically via the Assets API.
- Encode asset URLs to ensure functional API calls.
To access assets via the Assets API, you must have the following:
- A Public API Key.
- A Space Private Key.
See API Keys for more information.
You can delete assets by ID or by URL.
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.
curl --location --request DELETE \
'https://cdn.builder.io/api/v1/assets/ASSET_ID&apiKey=PUBLIC_API_KEY' \
--header 'Authorization: Bearer PRIVATE_API_KEY'
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.
curl --location --request DELETE \
'https://cdn.builder.io/api/v1/assets/by-url?url=ENCODED_ASSET_URL&apiKey=PUBLIC_API_KEY' \
--header 'Authorization: Bearer PRIVATE_API_KEY'
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.
To encode your URL, use the encodeURIComponent()
built-in JavaScript function.
encodeURIComponent("YOUR_URL");
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.