Complete guide to authenticating with the DRIP API
Authorization
Access Developer Portal
Create API Client
Copy and Store
Test the Key
DRIP_API_KEY=your_api_key_here DRIP_REALM_ID=your_realm_id_here DRIP_BASE_URL=https://api.drip.re/api/v1
class DripClient { constructor(apiKey, realmId) { this.apiKey = apiKey; this.realmId = realmId; this.baseUrl = 'https://api.drip.re/api/v1'; } async request(method, endpoint, data = null) { const url = `${this.baseUrl}${endpoint}`; const options = { method, headers: { 'Authorization': `Bearer ${this.apiKey}`, 'Content-Type': 'application/json' } }; if (data) { options.body = JSON.stringify(data); } const response = await fetch(url, options); if (!response.ok) { throw new Error(`API Error: ${response.status} ${response.statusText}`); } return response.json(); } // Helper methods async getRealm() { return this.request('GET', `/realms/${this.realmId}`); } async searchMembers(type, values) { return this.request('GET', `/realm/${this.realmId}/members/search?type=${type}&values=${values}`); } } // Usage const client = new DripClient(process.env.DRIP_API_KEY, process.env.DRIP_REALM_ID);
async function handleApiCall(apiCall) { try { return await apiCall(); } catch (error) { if (error.status === 401) { console.error('Authentication failed - check your API key'); // Redirect to re-authenticate or refresh key } else if (error.status === 403) { console.error('Insufficient permissions for this operation'); } else { console.error('API call failed:', error.message); } throw error; } }
async function testAuth() { try { const response = await fetch(`https://api.drip.re/api/v1/realms/${DRIP_REALM_ID}`, { headers: { 'Authorization': `Bearer ${DRIP_API_KEY}` } }); if (response.ok) { const realm = await response.json(); console.log('✅ Authentication successful!'); console.log(`Connected to realm: ${realm.name}`); } else { console.log('❌ Authentication failed'); } } catch (error) { console.error('Error testing authentication:', error); } }
401 Unauthorized
Authorization: Bearer YOUR_KEY
403 Forbidden
Rate Limiting
Was this page helpful?