All API requests require authentication using API keys or OAuth 2.0 tokens.
API Keys
Generating an API Key
- Log in to your MarketSage Dashboard
- Go to Settings → API Keys
- Click Generate New Key
- Give your key a descriptive name
- Copy the key immediately (it won't be shown again)
Using Your API Key
Include your API key in the Authorization header:
curl https://api.marketsage.africa/v2/contacts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"JavaScript Example
const response = await fetch('https://api.marketsage.africa/v2/contacts', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
});
const data = await response.json();Key Security
Never expose your API key in client-side code. Always make API calls from your server.
Best Practices
- Store API keys in environment variables
- Never commit keys to version control
- Rotate keys periodically
- Use separate keys for development and production
- Revoke unused keys immediately
Key Permissions
API keys can have different permission levels:
| Permission | Access |
|---|---|
| Read Only | GET requests only |
| Read/Write | GET, POST, PUT, DELETE |
| Admin | Full access including settings |
Error Responses
401 Unauthorized
{
"success": false,
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid or missing API key"
}
}403 Forbidden
{
"success": false,
"error": {
"code": "FORBIDDEN",
"message": "API key does not have permission for this action"
}
}