Authenticate with Dialect’s REST API using your API key for server-side notification sending
x-dialect-api-key
const response = await fetch(`https://alerts-api.dial.to/v2/${appId}/subscribers`, { method: 'GET', headers: { 'x-dialect-api-key': 'YOUR_API_KEY' } }); const { subscribers } = await response.json();
{ "error": "Unauthorized" }
{ "error": "Forbidden" }
async function sendNotificationSafely(appId: string, apiKey: string, message: any) { try { const response = await fetch(`https://alerts-api.dial.to/v2/${appId}/send`, { method: 'POST', headers: { 'x-dialect-api-key': apiKey, 'Content-Type': 'application/json' }, body: JSON.stringify(message) }); if (!response.ok) { const error = await response.json(); switch (response.status) { case 401: throw new Error('Invalid API key. Please check your credentials.'); case 403: throw new Error('Access denied. Check your app permissions.'); default: throw new Error(`HTTP ${response.status}: ${JSON.stringify(error)}`); } } return response.json(); } catch (error) { console.error('Failed to send notification:', error); throw error; } }
Was this page helpful?