Core APIsDevices
Core APIs

Devices API

Register and manage device tokens for push notifications

Overview

The Devices API allows you to register and manage device tokens for push notifications. When users install your mobile app, you register their device token with Flameup to enable push messaging. Web push support is coming soon.

Required Permission: devices:write for all device operations.

Supported Platforms

Flameup supports push notifications on three platforms:

Device Token Object

A device token in Flameup has the following structure:

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "workspace_id": "ws_abc123",
  "person_id": "550e8400-e29b-41d4-a716-446655440001",
  "device_token": "fMhT8K9x...(FCM token)",
  "platform": "ios",
  "device_name": "iPhone 15 Pro",
  "device_model": "iPhone16,1",
  "os_version": "17.2",
  "app_version": "2.1.0",
  "is_active": true,
  "is_valid": true,
  "last_used_at": "2024-01-20T14:45:00Z",
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-20T14:45:00Z"
}

Field Reference

FieldTypeRequiredDescription
tokenstringYesFCM/APNs token from the device
platformstringYesios or android (web coming soon)
device_namestringNoHuman-readable device name
device_modelstringNoDevice model identifier
os_versionstringNoOperating system version
app_versionstringNoYour app's version
The person_id is passed in the URL path, not in the request body.

Register a Device

Register a device token to enable push notifications for a user.

Endpoint: POST /api/v1/people/{person_id}/devices

The workspace is automatically determined from your API key, so you don't need to include it in the URL.
// After obtaining FCM token in your iOS app
async function registerIOSDevice(personId, fcmToken, deviceInfo) {
  const response = await fetch(
    `https://api.flameup.ai/api/v1/people/${personId}/devices`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${API_KEY}`
      },
      body: JSON.stringify({
        token: fcmToken,
        platform: 'ios',
        device_name: deviceInfo.name,        // e.g., "John's iPhone"
        device_model: deviceInfo.model,      // e.g., "iPhone16,1"
        os_version: deviceInfo.osVersion,    // e.g., "17.2"
        app_version: deviceInfo.appVersion   // e.g., "2.1.0"
      })
    }
  );

  return response.json();
}

Swift Example (getting the FCM token):

import FirebaseMessaging

Messaging.messaging().token { token, error in
    if let token = token {
        // Send this token to your backend
        registerDevice(fcmToken: token)
    }
}
curl -X POST "https://api.flameup.ai/api/v1/people/{person_id}/devices" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your_api_key" \
  -d '{
    "token": "fMhT8K9x...your_fcm_token",
    "platform": "ios",
    "device_name": "iPhone 15 Pro",
    "device_model": "iPhone16,1",
    "os_version": "17.2",
    "app_version": "2.1.0"
  }'

Response:

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "person_id": "550e8400-e29b-41d4-a716-446655440001",
  "device_token": "fMhT8K9x...",
  "platform": "ios",
  "is_active": true,
  "is_valid": true,
  "created_at": "2024-01-15T10:30:00Z"
}

List Devices

Retrieve all devices for a person.

Endpoint: GET /api/v1/people/{person_id}/devices

Query Parameters

ParameterTypeDescription
platformstringFilter by platform: ios, android (web coming soon)
is_activebooleanFilter by active status
limitintegerNumber of results (default 50, max 100)
offsetintegerPagination offset
// Get all devices for a user
const response = await fetch(
  `https://api.flameup.ai/api/v1/people/${personId}/devices`,
  {
    headers: {
      'Authorization': `Bearer ${API_KEY}`
    }
  }
);

const { devices } = await response.json();
console.log(`User has ${devices.length} registered devices`);

Update a Device

Update device information (e.g., when the app version changes).

To update device info, re-register the device with the new information. The device will be matched by token and updated.

Simply call the register endpoint again with the same token and updated fields:

// Re-register with updated info
const response = await fetch(
  `https://api.flameup.ai/api/v1/people/${personId}/devices`,
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${API_KEY}`
    },
    body: JSON.stringify({
      token: existingToken,
      platform: 'ios',
      app_version: '2.2.0',
      os_version: '17.3'
    })
  }
);

Delete a Device

Remove a device token (e.g., when user logs out or uninstalls).

Endpoint: DELETE /api/v1/people/{person_id}/devices/{token}

const response = await fetch(
  `https://api.flameup.ai/api/v1/people/${personId}/devices/${encodeURIComponent(deviceToken)}`,
  {
    method: 'DELETE',
    headers: {
      'Authorization': `Bearer ${API_KEY}`
    }
  }
);

if (response.ok) {
  console.log('Device unregistered');
}

Token Lifecycle

Device tokens have a lifecycle that Flameup manages automatically:

Registration

Token is registered when user enables notifications or installs the app.

  • is_active: true
  • is_valid: true

Active Use

Token is used for push delivery. last_used_at is updated with each use.

Token Refresh

FCM may issue a new token. Re-register with the new token; Flameup deduplicates by device.

Invalidation

If push delivery fails (uninstall, revoked permissions), token is marked:

  • is_valid: false
  • is_active: false

Handling Token Refresh

FCM tokens can change. Handle token refresh in your app:

extension AppDelegate: MessagingDelegate {
    func messaging(_ messaging: Messaging,
                   didReceiveRegistrationToken fcmToken: String?) {
        guard let token = fcmToken else { return }

        // Re-register with Flameup
        FlameupAPI.registerDevice(token: token)
    }
}

Best Practices

Register the device token after user login to associate it with the correct person:

async function onUserLogin(userId) {
  const fcmToken = await getFCMToken();
  const person = await flare.identifyUser(userId);
  await flare.registerDevice(person.id, fcmToken);
}

Troubleshooting

Push not working? Check these common issues:
IssueSolution
Token not registeredVerify person_id exists and token is valid
Wrong platformEnsure platform matches the device (ios/android)
Invalid tokenToken may have expired; request a fresh token from FCM
User not receivingCheck is_active and is_valid are both true
Notification blockedUser may have disabled notifications in device settings
Was this page helpful?
Built with Documentation.AI

Last updated today