OAuth 2.0
OAuth 2.0 provides secure, token-based authentication for third-party applications accessing Brevo on behalf of users.
OAuth Flow Overview
- Authorization Request: Redirect user to Brevo
- User Authorization: User grants permissions
- Authorization Code: Brevo redirects with code
- Access Token Exchange: Exchange code for tokens
- API Access: Use access token for requests
Authorization Endpoint
https://app.brevo.com/oauth/authorize? response_type=code& client_id=YOUR_CLIENT_ID& redirect_uri=YOUR_REDIRECT_URI& scope=email%20contacts& state=random_stringToken Exchange
curl -X POST "https://api.brevo.com/v3/oauth/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=authorization_code&code=AUTH_CODE&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&redirect_uri=YOUR_REDIRECT_URI"Access Token Usage
const response = await fetch('https://api.brevo.com/v3/account', { headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN', 'Accept': 'application/json' }});Scopes
email: Send transactional emailscontacts: Manage contacts and listscampaigns: Create and send campaignssms: Send SMS messageswebhooks: Manage webhooks
Token Refresh
const refreshToken = async () => { const response = await fetch('https://api.brevo.com/v3/oauth/token', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ grant_type: 'refresh_token', refresh_token: 'YOUR_REFRESH_TOKEN', client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET' }) }); return response.json();};