Managing assets
Learn how to upload and manage assets for use in your notification templates.
Overview
#Assets are files that you upload to Knock for use in your notification templates. You can upload images to be hosted by Knock and reference them via URL in your templates. This is useful for including logos, icons, and other visual elements in your notifications.
Account owners, admins, and members can manage assets from the Assets page under Content in the Knock dashboard sidebar. You can also manage assets with the Management API or the Knock CLI.
Assets are account-wide. An asset you upload is available in every environment.
Uploading assets
#To upload a new asset:
- Navigate to Content > Assets in your dashboard sidebar.
- Click the "Upload image" button.
- Select one or more image files from your computer. You can upload up to 20 files at a time.
File requirements
#Keep the following requirements in mind when uploading assets:
- File size. Each image must be 5 MB or less.
- File type. Only image files are supported. The dashboard accepts JPEG, PNG, GIF, and SVG files. The Management API and the CLI accept JPEG, PNG, and GIF files.
You can upload as many images as you need to your Knock account.
You can also upload an asset from the command line with knock asset upload.
Using assets in templates
#Once you've uploaded an asset, you can copy its URL and use it in your notification templates. To copy the URL:
- Navigate to Content > Assets in the Knock dashboard.
- Find the asset you want to use.
- Click the copy button to copy the asset URL to your clipboard.
You can then paste this URL into your notification templates wherever you need to reference the image, such as in email templates or in-app notifications.
Deleting assets
#To delete an asset:
- Navigate to Content > Assets in the Knock dashboard.
- Find the asset you want to delete.
- Click the delete button to remove the asset.
Managing assets with the Management API
#The Management API enables you to upload, list, and archive image assets programmatically. The API accepts JPEG, PNG, and GIF files up to 5 MB.
Uploading an asset
#Knock doesn't accept file bytes on the Management API itself. Instead, you upload the file directly to storage with a signed URL, then tell Knock to create the asset. Uploading an asset takes three requests:
Listing assets
#Use the list assets endpoint to retrieve a paginated list of the active assets in your account. Each entry includes the asset's id, filename, mime_type, and hosted url.
Archiving an asset
#Use the archive an asset endpoint to archive an asset by its id. As with deleting an asset in the dashboard, you should update any templates that reference the asset before you archive it.