Overview
The Migma.ai API provides programmatic access to our AI Email Engine that creates pixel-perfect, on-brand emails in 30 seconds. Build custom integrations, automate email creation workflows, track customer events, export to platforms like Mailchimp and HubSpot, and manage your entire email marketing infrastructure programmatically. Generate emails 200x faster and 95% cheaper with AI that learns your brand voice, fetches live content, and creates cross-client compatible HTML.Base URL
All API requests should be made to:Authentication
All API endpoints require authentication using API keys. Include your API key in theAuthorization header:
Authentication Guide
Learn how to create and manage API keys
API structure
The Migma.ai API is organized around REST principles:- Predictable resource-oriented URLs
- Standard HTTP response codes
- JSON request and response bodies
- Bearer token authentication
Request format
AllPOST, PATCH, and PUT requests should use JSON format:
Response format
All API responses follow a consistent structure:Success response
Error response
HTTP status codes
The API uses standard HTTP status codes:Rate limiting
API requests are rate limited based on your plan:
Rate limit information is included in response headers:
Pagination
List endpoints support pagination usinglimit and offset parameters:
Idempotency
POST endpoints accept an optional Idempotency-Key request header so you can safely retry a request after a network error or timeout without doing the work twice. It is opt-in: a request without the header is processed normally.
Replay behavior
Within a 24 hour window, the first request with a given key runs normally and its response is cached. After that:- Same key and same body returns the original cached response, with the same status and body. The replay carries the response header
Idempotent-Replayed: true, so you can tell a replay from a fresh execution. - Same key but a different body returns
409witherrorcodeIDEMPOTENCY_CONFLICT. Mint a fresh key whenever the request genuinely changes. - A key longer than 100 characters is rejected with
400and codeIDEMPOTENCY_KEY_INVALID.
429 (rate limited) and 5xx (server) responses are not cached, so a retry with the same key runs again. This is what makes a retry after a transient failure safe.
Recommended keys
Use a deterministic key derived from the logical operation, so the same retry always produces the same key:Anti-patterns
- Never use a random value such as
uuid()or a per-attempt timestamp likeDate.now(). A new value on each attempt defeats deduplication across retries and process restarts, which is exactly the case the key exists for. - Don’t hash the request body and use that as the key. The body is already part of the conflict check, and a body hash makes every distinct payload its own key rather than identifying one logical operation.
POST /v1/sending), sending or scheduling a campaign (POST /v1/campaigns/{id}/send and POST /v1/campaigns/{id}/schedule), and the contact write endpoints (POST /v1/contacts, POST /v1/contacts/bulk, and POST /v1/contacts/bulk-delete).
Brand / project scoping
An API key is scoped to your account, not to a single brand. Most resources (contacts, campaigns, segments, emails) live inside a project, so passprojectId on the requests that operate on them. Call GET /v1/projects first to discover the project IDs available to your key.
A resource that belongs to a different project than the one you reference returns 404, the same as a resource that does not exist. The API does not reveal that a resource exists in a project you did not name.
Events & Webhooks
Use webhooks to receive supported Migma API and contact events in your own app, queue, or automation tool:Events & Webhooks
Learn how to set up event notifications
API endpoints
Projects
Manage brand projects and imports:GET /v1/projects- List all projectsGET /v1/projects/{projectId}- Get project detailsPOST /v1/projects/import- Import a new brand
Project editing
Edit project content including knowledge base, images, and logos:GET /v1/projects/{projectId}/knowledge-base- List knowledge base entriesPOST /v1/projects/{projectId}/knowledge-base- Add knowledge base entryPUT /v1/projects/{projectId}/knowledge-base/{entryId}- Update entryDELETE /v1/projects/{projectId}/knowledge-base/{entryId}- Remove entryPOST /v1/projects/{projectId}/images- Add image (URL-only)PUT /v1/projects/{projectId}/images- Update image metadataDELETE /v1/projects/{projectId}/images- Remove imagePUT /v1/projects/{projectId}/logos- Update logos
Project editing endpoints require the
project:write permission.Email generation
Generate AI-powered, on-brand emails with async processing:POST /v1/projects/emails/generate- Generate an email (async)GET /v1/projects/emails/{conversationId}/status- Check generation status and getresult.emails[]withemailId, HTML, screenshots, and series orderGET /v1/emails/{emailId}- Fetch one generated email by IDPOST /v1/emails/{emailId}/edit- Prompt Migma to edit one generated email
Email validation
Comprehensive email testing and quality analysis:POST /v1/emails/validate/compatibility- Compatibility report for major webmail, desktop, and mobile clientsPOST /v1/emails/validate/links- Check all links for validityPOST /v1/emails/validate/spelling- AI-powered spell/grammar checkPOST /v1/emails/validate/deliverability- Predict inbox placementPOST /v1/emails/validate/all- Run all validation checks
Email validation API
Learn about email compatibility testing, link analysis, and deliverability prediction
Email previews
Generate screenshots on real devices and email clients:POST /v1/emails/previews- Create device previewsGET /v1/emails/previews/{previewId}- Get preview status & resultsGET /v1/emails/devices/supported- List supported preview device IDs (web, desktop, mobile)
Email preview API
See the auto-generated preview endpoint docs in the API reference
Contacts
Manage your contacts via API:GET /v1/contacts- List contactsPOST /v1/contacts- Add a contactPOST /v1/contacts/bulk- Bulk import contactsPOST /v1/contacts/bulk-delete- Batch delete contacts by emailPOST /v1/contacts/status- Change contact status
Campaigns
Create and manage named marketing campaigns with lifecycle tracking:GET /v1/campaigns- List campaignsPOST /v1/campaigns- Create a campaign from a generated emailGET /v1/campaigns/{id}- Get campaign detailsPOST /v1/campaigns/{id}/send- Send immediatelyPOST /v1/campaigns/{id}/schedule- Schedule for future deliveryPOST /v1/campaigns/{id}/cancel- Cancel a scheduled campaignPOST /v1/campaigns/{id}/archive- Archive a campaignPOST /v1/campaigns/{id}/unarchive- Restore an archived campaignGET /v1/campaigns/{id}/stats- Engagement statsGET /v1/campaigns/{id}/logs- Per-recipient delivery logs
Exports
Export generated emails to files or platforms:GET /v1/export/html/{conversationId}- Export as production HTMLGET /v1/export/mjml/{conversationId}- Export as MJMLGET /v1/export/pdf/{conversationId}- Export as PDFGET /v1/export/klaviyo/{conversationId}- Export for KlaviyoGET /v1/export/mailchimp/{conversationId}- Export for MailchimpPOST /v1/export/hubspot- Export for HubSpotGET /v1/export/status/{conversationId}- Poll export status
Error handling
Failed requests return the matching HTTP status code with this body:code field. Branch on the HTTP status code for programmatic handling, and treat error as a human-readable message for logging and display. For example, a missing scope returns HTTP 403 with error: "Insufficient permissions".
Environments
Use different API keys for different environments:Production
Development/Testing
Test keys are separate from production keys and don’t affect your production data or rate limits.
SDKs & libraries
Node.js / TypeScript (available now)
SDK Documentation
Full SDK guide — configuration, error handling, polling helpers, and all 14 resources
CLI (available now)
CLI Documentation
Full CLI guide — all commands, workflows, and configuration
Need help?
Quickstart
Get started in under 5 minutes
Events & Webhooks
Set up event notifications
Authentication
Learn about API keys and security
Join Discord
Connect with developers and get support