Assets API
Assets API
Section titled “Assets API”The Assets API provides endpoints for managing campaign assets, particularly images. Asset management includes both URL-based image insertion (free) and file uploads (premium feature).
Authentication
Section titled “Authentication”All asset endpoints require authentication via session cookies or API tokens.
Premium Requirements
Section titled “Premium Requirements”File upload operations require an active premium subscription. URL-based image insertion is available for all users.
Endpoints
Section titled “Endpoints”Request Upload URL
Section titled “Request Upload URL”Request a secure upload URL for file upload to Cloudflare Images.
POST /api/campaigns/{campaignSlug}/assets/upload-url
Request Body
Section titled “Request Body”{ "label": "string" // Descriptive label for the asset}
Response
Section titled “Response”{ "success": true, "uploadURL": "string", // Secure upload URL "imageId": "string" // Cloudflare image ID}
Error Responses
Section titled “Error Responses”401 Unauthorized
- User not authenticated403 Forbidden
- Premium subscription required404 Not Found
- Campaign not found or not accessible400 Bad Request
- Missing or invalid label
Confirm Upload
Section titled “Confirm Upload”Confirm successful upload and save asset to database.
POST /api/campaigns/{campaignSlug}/assets/confirm-upload
Request Body
Section titled “Request Body”{ "imageId": "string", // Cloudflare image ID from upload URL request "label": "string" // Descriptive label for the asset}
Response
Section titled “Response”{ "success": true, "url": "string" // Public URL of the uploaded image}
Error Responses
Section titled “Error Responses”401 Unauthorized
- User not authenticated403 Forbidden
- Premium subscription required404 Not Found
- Campaign not found or not accessible400 Bad Request
- Missing parameters or upload not completed500 Internal Server Error
- Upload verification failed
Usage Flow
Section titled “Usage Flow”File Upload (Premium)
Section titled “File Upload (Premium)”- Request upload URL with asset label
- Upload file directly to Cloudflare using the provided URL
- Confirm upload completion to save asset in database
- Use returned public URL in content
URL-based Images (Free)
Section titled “URL-based Images (Free)”For free users, images can be added directly using external URLs without going through the upload process.
Data Model
Section titled “Data Model”interface Asset { id: number label: string // User-provided descriptive label cloudflareId: string // Unique Cloudflare image identifier url: string // Public URL for the image campaignId: number // Associated campaign userId: string // Asset owner createdAt: Date // Creation timestamp}
Integration
Section titled “Integration”Editor Integration
Section titled “Editor Integration”Assets are integrated with the rich text editor through the image uploader component:
- Toolbar button opens upload dialog
- Users can choose between URL and file upload modes
- Premium users see file upload option
- Free users are shown premium upgrade prompts for file uploads
HTML Rendering
Section titled “HTML Rendering”When assets are used in content:
- Alt text is populated from the asset label
- Images display with descriptive labels below
- Proper accessibility attributes are included
Error Handling
Section titled “Error Handling”The API provides detailed error responses for various failure scenarios:
- Authentication failures
- Permission violations (premium required)
- Upload verification issues
- Invalid parameters
- Network or service errors
Clients should handle these errors gracefully and provide appropriate user feedback.