Authentication
Learn how to authenticate with the Moqup API using API keys.
The Moqup API uses API keys for authentication. This guide covers how to create, use, and manage your API keys securely.
API Keys
Overview
API keys are the authentication method for the Moqup API:
- Simple to implement
- Workspace-scoped access
- Granular permission levels
- Support for multiple keys per workspace
Creating API Keys
- Go to Settings > API > API Keys
- Click Create New Key
- Name your key (e.g., "CI/CD Integration")
- Select permissions
- Copy the key immediately
Using API Keys
Include in the Authorization header:
curl https://moqup.io/api/v1/projects \
-H "Authorization: Bearer YOUR_API_KEY"Or use the X-API-Key header:
curl https://moqup.io/api/v1/projects \
-H "X-API-Key: YOUR_API_KEY"Key Format
All Moqup API keys start with the mq_ prefix:
mq_abc123xyz...This makes it easy to identify Moqup keys in your configuration.
Permissions
Available Permissions
| Permission | Access |
|---|---|
read | View projects, files, annotations, and clients |
write | Create and modify resources (includes read) |
admin | Full access including delete operations |
Permission Inheritance
writepermission includesreadaccessadminpermission includes all other permissions
Choosing Permissions
Follow the principle of least privilege:
| Use Case | Recommended |
|---|---|
| Read-only dashboard | read |
| CI/CD upload | write |
| Full integration | admin |
Key Management
Managing Existing Keys
In your API settings, you can:
- View last used timestamp
- See key prefix for identification
- Revoke access instantly
- Create new keys as needed
Revoking Keys
To revoke a compromised or unused key:
- Go to Settings > API > API Keys
- Find the key by its name or prefix
- Click Revoke
- The key is immediately invalidated
Expiration
Keys can be set to expire:
- Never (default)
- Custom expiration date
- Expired keys are automatically rejected
Best Practices
Security
- One key per integration: Easier to revoke if compromised
- Minimum permissions: Only grant what's needed
- Rotate regularly: Monthly or quarterly rotation recommended
- Never commit to code: Use environment variables
Environment Variables
Store keys securely:
# .env.local (never commit this file)
MOQUP_API_KEY=mq_your_api_key_hereUse in your code:
const apiKey = process.env.MOQUP_API_KEY;
fetch('https://moqup.io/api/v1/projects', {
headers: {
'Authorization': `Bearer ${apiKey}`
}
});Server-Side Only
Never expose API keys in client-side code:
- Store in server environment
- Use in API routes
- Proxy requests through your backend
- Include in frontend bundles
- Store in localStorage
- Expose in client-side JavaScript
Error Handling
Authentication Errors
{
"error": {
"message": "Invalid API key.",
"code": 401
}
}Common Errors
| Error | Cause | Solution |
|---|---|---|
| Missing API key | No header provided | Add Authorization header |
| Invalid API key format | Key doesn't start with mq_ | Check key format |
| Invalid API key | Key not found or wrong | Verify key is correct |
| API key has been revoked | Key was revoked | Create a new key |
| API key has expired | Key past expiration date | Create a new key |
Handling Errors
async function apiRequest(endpoint) {
const response = await fetch(`https://moqup.io/api/v1${endpoint}`, {
headers: {
'Authorization': `Bearer ${process.env.MOQUP_API_KEY}`
}
});
if (response.status === 401) {
const error = await response.json();
console.error('Authentication failed:', error.error.message);
// Handle: check key, create new one, etc.
}
return response.json();
}Rate Limiting
Limits by Plan
Authentication-related limits apply per API key:
| Plan | Requests/minute | Requests/day |
|---|---|---|
| Free | 30 | 1,000 |
| Pro | 60 | 10,000 |
| Team | 120 | 50,000 |
Rate Limit Headers
Every response includes rate limit information:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1678900000Testing
Development Keys
Best practices for testing:
- Create separate keys for development
- Use
readpermission during testing - Revoke test keys before production
Verifying Setup
Test your authentication:
curl -v https://moqup.io/api/v1/projects \
-H "Authorization: Bearer YOUR_API_KEY"A successful response returns your projects list.
Next Steps
- Projects API - Start making requests
- Files API - Upload and manage files
- Rate Limits - Understand usage limits