Uploads
Set MAILCOACH_API_URL and MAILCOACH_TOKEN as shown in Authentication. Upload images to get hosted URLs you can use in the HTML of campaigns, templates and automation mails.
Upload images
Send up to 10 JPEG, PNG, GIF or WebP images per request, each up to 8 MB. SVG images are not accepted. Send files as multipart form data:
curl -X POST "$MAILCOACH_API_URL/uploads" \ -H "Authorization: Bearer $MAILCOACH_TOKEN" \ -H 'Accept: application/json' \ -F 'images[0][file]=@header.png' \ -F 'images[1][file]=@product.jpg'
Or send JSON with a name and the base64-encoded file for each image, without a data: URI prefix:
curl -X POST "$MAILCOACH_API_URL/uploads" \ -H "Authorization: Bearer $MAILCOACH_TOKEN" \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ -d "{\"images\":[{\"name\":\"header.png\",\"base64\":\"$(base64 < header.png | tr -d '\n')\"}]}"
All images are validated before any are stored. The response has status 201 and lists the hosted images in the order you sent them:
{ "data": [ { "uuid": "5d1b3a1e-6f8b-4a3e-9c3e-0f6c2b8d9a41", "name": "header.png", "url": "https://<hosted-image-url>/header.png" } ] }
Use an uploaded image
Uploading doesn’t change any email. Put the returned url in an <img> tag in the email’s HTML, then save it with the matching update endpoint, for example Update a campaign. Animated GIFs keep their animation.
Error handling
A 422 response lists the images that failed validation, for example a file that is too large or not an image. Nothing is stored in that case.