API Keys
Migma.ai uses API keys to authenticate requests. Your API keys carry many privileges, so be sure to keep them secure! Do not share your API keys in publicly accessible areas such as GitHub, client-side code, etc.Creating an API Key
Navigate to Settings
Log in to migma.ai and go to Settings → API Integration
Using Your API Key
Include your API key in theAuthorization header of every request:
Example Request
Node.js SDK
cURL
JavaScript
Python
API Key Permissions
When creating an API key, you can grant specific permissions to limit what the key can access:| Permission | Description |
|---|---|
audience:read | View subscribers, tags, and audience segments |
audience:write | Add, update subscribers, manage tags, create segments |
email:read | View email templates and sending history |
email:send | Send emails to subscribers using templates |
email:validate | Test email compatibility, check links, and analyze deliverability |
email:preview | Generate email previews across multiple devices and email clients |
template:read | Read and use email templates |
domain:read | View sending domains and their verification status |
domain:write | Add, verify, update, and remove sending domains |
project:write | Import projects and manage project resources |
webhook:read | List and view webhook configurations |
webhook:write | Create, update, and delete webhooks for real-time notifications |
Environment-Specific Keys
Use different API keys for different environments:Development
Production
Test keys start with
sk_test_ and production keys start with sk_live_Security Best Practices
1. Store Keys Securely
Never hardcode API keys in your source code. Use environment variables:Node.js SDK
JavaScript
2. Use Environment Variables
.env
Node.js SDK
JavaScript
3. Rotate Keys Regularly
Create new API keys periodically and revoke old ones:- Create a new API key with the same permissions
- Update your application to use the new key
- Test thoroughly
- Revoke the old key
4. Use Read-Only Keys When Possible
If your application only needs to read data, create a key with only read permissions:5. Monitor Key Usage
Check your API key usage regularly in the Migma dashboard:- Go to Settings → API Integration → API Keys
- View last used date for each key
- Check for any unexpected usage patterns
Key Management
Viewing Your Keys
Navigate to Settings → API Integration → API Keys to see:- Key name and ID (first 8 characters)
- Permissions granted
- Creation date
- Last used date
- Usage statistics
Revoking a Key
If a key is compromised or no longer needed:Error Responses
401 Unauthorized
Your API key is invalid or missing:- API key not included in Authorization header
- Wrong format (must be
Bearer YOUR_KEY) - Key has been revoked
- Using test key in production environment
403 Forbidden
Your API key doesn’t have permission for this action:Rate Limiting
API keys are subject to rate limits based on your plan:| Plan | Rate Limit |
|---|---|
| Free | 10 requests/minute |
| Pro | 100 requests/minute |
| Enterprise | Custom limits |
429 Too Many Requests response:
Testing Authentication
Test your API key with a simple request:cURL