Unsubscribe from Topic
Unsubscribes the device from a Firebase push topic.
Description
The unsubscribeFromTopic helper unsubscribes the device from a Firebase push topic. Native unsubscribes only when the store's push plugin is Firebase. The topic is trimmed before it is sent.
Call it as Superfans.helpers.marketing.unsubscribeFromTopic.
Function Signature
await Superfans.helpers.marketing.unsubscribeFromTopic({
topic: "sale"
});| Parameter | Type | Required | Description |
|---|---|---|---|
topic | String | Yes | Firebase push topic. Must be a non-empty string. Leading and trailing spaces are removed. |
Structure of Response
| Status | Response |
|---|---|
| Success | { "status": "success", "message": "Unsubscribed from topic successfully" } |
| Invalid topic | { "status": "error", "errorId": 400, "errorHandle": "invalid-params", "message": "Topic should be provided." } |
| Firebase disabled | { "status": "error", "errorId": 503, "errorHandle": "firebase-disabled", "message": "Firebase is not enabled." } |
| Unexpected Error | { "status": "error", "errorId": 500, "errorHandle": "unknown-error", "message": "Something unexpected happened" } |
Example Usage
try {
await Superfans.helpers.marketing.unsubscribeFromTopic({
topic: "sale"
});
} catch (error) {
await Superfans.actions.showToast({
title: "Something went wrong",
message: error.message || "Please try again."
});
}Best Practices
- Pass the same topic string that was used with
subscribeToTopic. - Handle errors with
try/catch. A rejected call usesstatus,errorId,errorHandle, andmessage.
Caveats
- A missing, non-string, or blank topic is rejected before anything is sent.
- Native unsubscribes only when Firebase is the store's push plugin. If Firebase is disabled, the call rejects with
firebase-disabled.
Updated about 2 hours ago
Did this page help you?