|
| 1 | +--- |
| 2 | +title: 'Manage Topics' |
| 3 | +description: "Learn how to use topics to group subscribers and broadcast notifications to thousands of users with a single API call." |
| 4 | +icon: 'Tags' |
| 5 | +--- |
| 6 | + |
| 7 | +Novu provides multiple ways to manage topics, either through the dashboard or the API. Both options give you flexibility depending on whether you prefer a UI-based workflow or direct API integration. |
| 8 | + |
| 9 | +### Create a Topic |
| 10 | + |
| 11 | +Creating a topic defines a new group of subscribers that can later be targeted in workflow triggers. You can create a topic either from the Dashboard or using the API: |
| 12 | + |
| 13 | +#### Create a topic via dashboard |
| 14 | + |
| 15 | +1. Login to the Novu dashboard |
| 16 | +2. Go to **Topics** in the left navigation. |
| 17 | +3. Click the **Create Topic** button. |
| 18 | +4. Provide a unique **Name** and **Topic Key**. |
| 19 | +5. Click on the **Create topic** button. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +#### Create a topic via API |
| 24 | + |
| 25 | +You can create a new topic using the `topics.create` method. |
| 26 | + |
| 27 | +```ts |
| 28 | +import { Novu } from "@novu/api"; |
| 29 | + |
| 30 | +const novu = new Novu({ secretKey: "YOUR_SECRET_KEY_HERE", }); |
| 31 | + |
| 32 | +async function run() { |
| 33 | + const result = await novu.topics.create({ |
| 34 | + key: "task:12345", |
| 35 | + name: "Task Title", |
| 36 | + }); |
| 37 | + |
| 38 | + console.log(result); |
| 39 | +} |
| 40 | + |
| 41 | +run(); |
| 42 | +``` |
| 43 | + |
| 44 | +Novu also supports on-the-fly topic creation. If you attempt to add subscribers to a topic key that doesn't exist for the selected environment and organization, Novu will automatically create a new topic named `Autogenerated-<TOPIC_KEY>` and assign the subscribers to it. |
| 45 | + |
| 46 | +This auto-generated topic can then be renamed and managed just like any other topic created manually. |
| 47 | + |
| 48 | +### Retrieve a topic |
| 49 | + |
| 50 | +Retrieving a topic allows you to confirm that it exists and view its details, including the name and key. |
| 51 | + |
| 52 | +```ts |
| 53 | +import { Novu } from "@novu/api"; |
| 54 | + |
| 55 | +const novu = new Novu({ secretKey: "YOUR_SECRET_KEY_HERE", }); |
| 56 | + |
| 57 | +async function run() { |
| 58 | + const result = await novu.topics.get("<value>"); |
| 59 | + |
| 60 | + console.log(result); |
| 61 | +} |
| 62 | + |
| 63 | +run(); |
| 64 | +``` |
| 65 | + |
| 66 | +### Update a topic name |
| 67 | + |
| 68 | +You can update the display name of a topic to better reflect its purpose. The `topicKey` itself is permanent and cannot be modified after the topic is created. |
| 69 | + |
| 70 | +#### Update a topic name via dashboard |
| 71 | + |
| 72 | +1. Log in to the Novu dashboard |
| 73 | +2. From the **Topics** page, click on the topic you want to update |
| 74 | +3. From the Overview tab, update the name of the topic |
| 75 | +4. Click **Save changes** to save. |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +#### Update a topic name via API |
| 80 | + |
| 81 | +Use the `topics.update` method with the topic's key to update the name of a topic |
| 82 | + |
| 83 | +```ts |
| 84 | +import { Novu } from "@novu/api"; |
| 85 | + |
| 86 | +const novu = new Novu({ secretKey: "YOUR_SECRET_KEY_HERE" }); |
| 87 | + |
| 88 | +async function run() { |
| 89 | + const result = await novu.topics.update( |
| 90 | + { name: "Updated Topic Name" }, |
| 91 | + "task:12345" // topicKey |
| 92 | + ); |
| 93 | + |
| 94 | + console.log(result); |
| 95 | +} |
| 96 | + |
| 97 | +run(); |
| 98 | +``` |
| 99 | + |
| 100 | +### List all topics |
| 101 | + |
| 102 | +Listing topics lets you see all groups that have been created in the current environment. This is useful for confirming available topic keys and checking which topics exist before triggering workflows. |
| 103 | + |
| 104 | +#### Get list of topics via dashboard |
| 105 | +1. Log in to the Novu dashboard |
| 106 | +2. From the **Topics** page, you will see the list of all topics that have bee created either from the dashboard or using the API. |
| 107 | + |
| 108 | +#### List all topics via API |
| 109 | +Use the `topics.list` method. |
| 110 | + |
| 111 | +```ts |
| 112 | +import { Novu } from "@novu/api"; |
| 113 | + |
| 114 | +const novu = new Novu({ secretKey: "YOUR_SECRET_KEY_HERE", }); |
| 115 | + |
| 116 | +async function run() { |
| 117 | + const result = await novu.topics.list({}); |
| 118 | + console.log(result); |
| 119 | +} |
| 120 | + |
| 121 | +run(); |
| 122 | +``` |
| 123 | + |
| 124 | +### Delete a topic |
| 125 | + |
| 126 | +Deleting a topic permanently removes the grouping, but it does not affect the subscribers themselves. This action is irreversible, so be sure you no longer need the topic before deleting it. |
| 127 | + |
| 128 | +#### Delete a topic via dashboard |
| 129 | + |
| 130 | +1. Log in to the Novu dashboard |
| 131 | +2. From the **Topics** page, click on the topic you want to delete. |
| 132 | +3. Click **Delete topic**. |
| 133 | +4. A modal will appear; click **Delete topic** again to confirm. |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | +#### Delete a topic via API |
| 138 | + |
| 139 | +Use the `topics.delete` method with the topic's key. |
| 140 | + |
| 141 | +```ts |
| 142 | +import { Novu } from "@novu/api"; |
| 143 | + |
| 144 | +const novu = new Novu({ secretKey: "YOUR_SECRET_KEY_HERE" }); |
| 145 | + |
| 146 | +async function run() { |
| 147 | + const result = await novu.topics.delete("task:12345"); // topicKey |
| 148 | + |
| 149 | + console.log(result); |
| 150 | +} |
| 151 | + |
| 152 | +run(); |
| 153 | +``` |
| 154 | + |
| 155 | +## Manage topic subscriptions |
| 156 | + |
| 157 | +A topic subscription is a relationship between a subscriber and a topic. Subscriptions track which subscribers belong to which topics. |
| 158 | + |
| 159 | +Subscribers can be added to or removed from a topic at any time, either from the Novu dashboard or through the API. |
| 160 | + |
| 161 | +### Add subscribers to a topic |
| 162 | + |
| 163 | +Adding subscribers to a topic ensures that they receive all notifications sent to that topic. You can add individual subscribers or multiple subscribers at once, depending on your needs. |
| 164 | + |
| 165 | +#### Add subscribers to a topic via dashboard |
| 166 | + |
| 167 | +1. Log in to the Novu dashboard. |
| 168 | +2. From the **Topics** page, select the topic you want to manage. |
| 169 | +3. Go to the **Subscriptions** tab. |
| 170 | +4. Search for and select the subscribers you want to add either using Email, Name, Phone or `SubscriberId`. |
| 171 | +5. Select the subscriber to add them to the topic. |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | +#### Add subscribers to a topic via API |
| 176 | + |
| 177 | +Use the `topics.subscriptions.create()` method to add one or more subscribers to a topic, referencing the topic's key and an array of `subscriberIds`. |
| 178 | + |
| 179 | +```ts |
| 180 | +import { Novu } from "@novu/api"; |
| 181 | + |
| 182 | +const novu = new Novu({ secretKey: "YOUR_SECRET_KEY_HERE" }); |
| 183 | + |
| 184 | +async function run() { |
| 185 | + const result = await novu.topics.subscriptions.create("task:12345", { |
| 186 | + subscriberIds: [ |
| 187 | + "subscriberId1", |
| 188 | + "subscriberId2", |
| 189 | + ], |
| 190 | + }); |
| 191 | + |
| 192 | + console.log(result); |
| 193 | +} |
| 194 | + |
| 195 | +run(); |
| 196 | +``` |
| 197 | + |
| 198 | +### Remove subscribers from a topic |
| 199 | + |
| 200 | +Removing subscribers from a topic stops them from receiving notifications sent to that topic. The subscribers remain active in Novu but will no longer be part of that specific group. |
| 201 | + |
| 202 | +#### Remove subscribers from a topic via dashboard |
| 203 | + |
| 204 | +1. Log in to the Novu dashboard. |
| 205 | +2. From the **Topics** page, select the topic. |
| 206 | +3. Go to the **Subscriptions** tab. |
| 207 | +4. Locate the subscriber(s) you want to remove. |
| 208 | +5. Click on the delete icon next to the user who you want to remove from the topic. |
| 209 | +6. In the menu that appears, click **Remove**. |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | +#### Remove subscribers from a topic via API |
| 214 | + |
| 215 | +You can use the API to remove one or more subscribers from the topic which a single API call by providing their `subscriberIds`. |
| 216 | + |
| 217 | +```ts |
| 218 | +import { Novu } from "@novu/api"; |
| 219 | + |
| 220 | +const novu = new Novu({ |
| 221 | + secretKey: "YOUR_SECRET_KEY_HERE", |
| 222 | +}); |
| 223 | + |
| 224 | +async function run() { |
| 225 | + const result = await novu.topics.subscriptions.delete({ |
| 226 | + subscriberIds: [ |
| 227 | + "subscriberId1", |
| 228 | + "subscriberId2", |
| 229 | + ], |
| 230 | + }, "<value>"); |
| 231 | + |
| 232 | + console.log(result); |
| 233 | +} |
| 234 | + |
| 235 | +run(); |
| 236 | +``` |
| 237 | + |
| 238 | +### List subscribers in a topic |
| 239 | + |
| 240 | +You can view all subscribers currently assigned to a specific topic. |
| 241 | + |
| 242 | +#### List subscribers in a topic via dashboard |
| 243 | + |
| 244 | +1. Log in to the Novu dashboard. |
| 245 | +2. From the **Topics** page, select the topic. |
| 246 | +3. Go to the **Subscriptions** tab to see the list of subscribers currently assigned. |
| 247 | + |
| 248 | + |
| 249 | + |
| 250 | +#### List subscribers in a topic via API |
| 251 | + |
| 252 | +```ts |
| 253 | +import { Novu } from "@novu/api"; |
| 254 | + |
| 255 | +const novu = new Novu({ secretKey: "YOUR_SECRET_KEY_HERE" }); |
| 256 | + |
| 257 | +async function run() { |
| 258 | + const result = await novu.topics.subscriptions.list({ |
| 259 | + topicKey: "task:12345", |
| 260 | + }); |
| 261 | + |
| 262 | + console.log(result); |
| 263 | +} |
| 264 | + |
| 265 | +run(); |
| 266 | +``` |
| 267 | + |
| 268 | +### Check subscriber subscription |
| 269 | + |
| 270 | +You can confirm whether a specific subscriber belongs to a given topic. This is useful when validating membership before triggering workflows or debugging unexpected notification behavior. |
| 271 | + |
| 272 | +#### Check subscriber subscription via dashboard |
| 273 | + |
| 274 | +1. Log in to the Novu dashboard. |
| 275 | +2. From the **Topics** page, select the topic. |
| 276 | +3. Go to the **Subscriptions** tab. |
| 277 | +4. Use the search bar to look up the subscriber. If they are subscribed, they will appear in the list. |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | +#### Check subscriber subscription via API |
| 282 | + |
| 283 | +```ts |
| 284 | +import { Novu } from "@novu/api"; |
| 285 | + |
| 286 | +const novu = new Novu({ secretKey: "YOUR_SECRET_KEY_HERE" }); |
| 287 | + |
| 288 | +async function run() { |
| 289 | + const result = await novu.topics.subscribers.retrieve( |
| 290 | + "task:12345", // topicKey |
| 291 | + "subscriber-id-to-check" // subscriberId |
| 292 | + ); |
| 293 | + |
| 294 | + console.log(result); |
| 295 | +} |
| 296 | + |
| 297 | +run(); |
| 298 | +``` |
| 299 | + |
| 300 | +## Explore the topics APIs |
| 301 | + |
| 302 | +These are commonly used topics APIs. Explore all topics APIs on topics [API Reference documentation](/api-reference/topics/topic-schema). |
| 303 | + |
| 304 | +<Cards> |
| 305 | + <Card |
| 306 | + title="Create a topic API" |
| 307 | + href="/api-reference/topics/create-a-topic" |
| 308 | + description="Create a new topic with name and topicKey" |
| 309 | + /> |
| 310 | + <Card |
| 311 | + title="Update a topic API" |
| 312 | + href="/api-reference/topics/update-a-topic" |
| 313 | + description="Update existing topic using topicKey" |
| 314 | + /> |
| 315 | + <Card |
| 316 | + title="Create topic subscription API" |
| 317 | + href="/api-reference/topics/create-topic-subscriptions" |
| 318 | + description="Add multiple subscribers into a topic" |
| 319 | + /> |
| 320 | + <Card |
| 321 | + title="List topic subscriptions API" |
| 322 | + href="/api-reference/topics/list-topic-subscriptions" |
| 323 | + description="List all subscribers present in a single topic" |
| 324 | + /> |
| 325 | + <Card |
| 326 | + title="List all topics API" |
| 327 | + href="/api-reference/topics/list-all-topics" |
| 328 | + description="List all topics in an environment" |
| 329 | + /> |
| 330 | + <Card |
| 331 | + title="Check subscriber subscription API" |
| 332 | + href="/api-reference/topics/check-topic-subscriber" |
| 333 | + description="Check if a subscriber is present in a topic" |
| 334 | + /> |
| 335 | +</Cards> |
0 commit comments