Actions4
- FCM Token Actions
- Notifications Actions
Overview
This node interacts with Google Firebase Notifications, specifically managing Firebase Cloud Messaging (FCM) tokens and sending notifications. The "Remove Stale" operation under the "FCM Token" resource is designed to clean up outdated or unused device tokens from a specified Firestore collection. It removes tokens and user documents that were created before a given timestamp, helping maintain an up-to-date and efficient token database.
Common scenarios for this node include:
- Periodically cleaning stale FCM tokens to reduce clutter and improve notification delivery efficiency.
- Managing device tokens in bulk by removing those that are no longer valid or associated with inactive users.
- Maintaining Firestore collections by deleting old user entries and their related device tokens based on creation time.
Example use case:
- A mobile app backend uses this node to remove all device tokens and user records created before a certain date, ensuring only active devices receive push notifications.
Properties
Name | Meaning |
---|---|
Collection | The name of the Firestore collection containing the tokens and user documents to clean. |
Created Before | Timestamp in milliseconds; tokens and user documents created before this time will be removed. Example: 1519211809934 |
Output
The output JSON contains two fields:
deletedDeviceIds
: An array of device ID strings representing the individual device tokens that were deleted because they were stale.deletedUserIds
: An array of user document IDs that were deleted because all their device tokens were stale or missing.
This output helps track exactly which tokens and user records were removed during the cleanup operation.
Dependencies
- Requires a configured Google Firebase service account credential with access to Firestore and Firebase Cloud Messaging.
- The node initializes the Firebase Admin SDK using the provided project ID, client email, and private key.
- Firestore must have a structure where user documents contain a subcollection named
"device_ids"
holding device token documents withcreated_at
timestamps.
Troubleshooting
No credentials got returned!
This error indicates missing or invalid API credentials. Ensure the Google Firebase service account credentials are properly set up in n8n.User collection not found / No data found for the user
Occurs if the specified collection or user document does not exist. Verify the collection name and user IDs are correct.Permission errors from Firestore
Make sure the service account has sufficient permissions to read and delete documents in the specified Firestore collections.Empty collections or no tokens deleted
If no tokens or users are deleted, verify theCreated Before
timestamp is correctly set and that there are documents older than this value.