MessagingMessaging APIs
Messaging

Messaging APIs

Send push notifications and emails to your users

Overview

Flameup provides APIs to send messages directly to your users. Use these for transactional notifications triggered by user actions like order confirmations, password resets, and account alerts.


Push Notifications

Send push notifications to a user's registered devices.

Required: User must have a registered device token. See Devices API for registration.

Send Push Notification

Endpoint: POST /api/v1/push/send

async function sendPush(personId, title, body, options = {}) {
  const response = await fetch(
    `https://api.flameup.ai/api/v1/push/send`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${API_KEY}`
      },
      body: JSON.stringify({
        person_id: personId,
        title: title,
        body: body,
        ...options
      })
    }
  );

  return response.json();
}

// Example: Order confirmation
await sendPush('550e8400-e29b-41d4-a716-446655440000',
  'Order Confirmed!',
  'Your order #ORD-12345 has been confirmed. Total: $99.99',
  {
    action_url: 'myapp://orders/ORD-12345',
    ios_badge: 1
  }
);

Request Body

FieldTypeRequiredDescription
person_idstringYesFlameup person UUID
titlestringYesNotification title (max 255 chars)
bodystringYesNotification body text
platformstringNoTarget platform: ios, android, or all (default). Web coming soon.
image_urlstringNoURL for rich notification image
action_urlstringNoDeep link URL when notification is tapped
prioritystringNoDelivery priority: low, normal, high
ttlintegerNoTime to live in seconds
custom_dataobjectNoCustom key-value payload for your app

iOS Options

FieldTypeDescription
ios_badgeintegerApp badge count
ios_soundstringNotification sound (e.g., default)
ios_categorystringAction category for interactive notifications

Android Options

FieldTypeDescription
android_channel_idstringNotification channel ID
android_iconstringNotification icon resource name
android_colorstringIcon color (e.g., #FF0000)
android_soundstringNotification sound

Response

{
  "message_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "sent",
  "sent_at": "2024-01-15T10:30:00Z",
  "provider": "fcm",
  "provider_id": "projects/myapp/messages/abc123"
}
FieldDescription
message_idFlameup message ID
statuspending, sent, delivered, or failed
sent_atTimestamp when sent
providerPush provider used (fcm)
provider_idExternal message ID from provider
errorError message (only if failed)

Push Notification Examples

// Order confirmation
await sendPush(personId, 'Order Confirmed!',
  'Your order #ORD-12345 is confirmed. Total: $99.99', {
    action_url: 'myapp://orders/ORD-12345',
    ios_badge: 1
});

// Shipping notification
await sendPush(personId, 'Your order has shipped!',
  'Track your package: 1Z999AA10123456784', {
    action_url: 'myapp://tracking/1Z999AA10123456784'
});

// Delivered notification
await sendPush(personId, 'Package delivered!',
  'Your order #ORD-12345 has been delivered.', {
    action_url: 'myapp://orders/ORD-12345/review'
});

Email

Send transactional emails to your users.

Send Email

Endpoint: POST /api/v1/messaging/send-email

async function sendEmail(to, subject, htmlBody, textBody) {
  const response = await fetch(
    'https://api.flameup.ai/api/v1/messaging/send-email',
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${API_KEY}`
      },
      body: JSON.stringify({
        workspaceId: WORKSPACE_ID,
        to: Array.isArray(to) ? to : [to],
        subject: subject,
        htmlBody: htmlBody,
        textBody: textBody
      })
    }
  );

  return response.json();
}

// Example: Password reset email
await sendEmail(
  'user@example.com',
  'Reset Your Password',
  '<h1>Password Reset</h1><p>Click <a href="https://myapp.com/reset?token=abc123">here</a> to reset your password.</p>',
  'Click this link to reset your password: https://myapp.com/reset?token=abc123'
);

Request Body

FieldTypeRequiredDescription
workspaceIdstringYesYour workspace ID
toarrayYesArray of recipient email addresses
subjectstringYesEmail subject line
htmlBodystringNoHTML email body
textBodystringNoPlain text email body
fromstringNoSender email address
replyTostringNoReply-to email address
At least one of htmlBody or textBody must be provided.

Response

{
  "success": true,
  "messageId": "550e8400-e29b-41d4-a716-446655440000",
  "message": "Email sent successfully",
  "provider": "resend"
}

Error Handling

Handle these common error cases in your integration.

Push Errors

{
  "message_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "failed",
  "error": "No valid device tokens found for user"
}

Common push errors:

  • No device tokens registered for user
  • Invalid or expired device token
  • FCM configuration missing for workspace

Email Errors

{
  "success": false,
  "error": "Invalid recipient email address"
}

Common email errors:

  • Invalid email format
  • Email provider configuration missing
  • Rate limit exceeded

Handling in Code

async function sendNotification(personId, title, body, options) {
  try {
    const result = await sendPush(personId, title, body, options);

    if (result.status === 'failed') {
      console.error('Push failed:', result.error);
      // Fallback to email or in-app notification
      return null;
    }

    return result;
  } catch (error) {
    console.error('Network error:', error);
    throw error;
  }
}

Best Practices

The Push API requires the Flameup person_id (UUID), not your external user ID. Look up the person first or store the person_id when you create users:

// When creating a user, store the person_id
const person = await createPerson({ userId: 'user_123', ... });
// Save person.id for later push notifications