You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/platform/workflow/contexts.mdx
+50-25Lines changed: 50 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ In simple terms, a context acts like an extended version of the payload. While t
11
11
12
12
<Callouttype='warn'>You can pass a maximum of five contexts per workflow trigger and the serialized `data` object for each context is limited to 64KB.</Callout>
13
13
14
-
## How Context works
14
+
## How context works
15
15
16
16
Imagine you have a single subscriber entity, `[email protected]`, who uses two different applications you offer: "Notion Email" and "Notion Calendar". You want to send notifications specific to each application.
-**Multi-tenancy and App Routing**: Use a tenant or app context to dynamically alter notification content, branding, or logic for different customers or applications from a single workflow.
69
-
-**Shared Chat Credentials**: For chat providers like Slack or MS Teams, store workspace-level credentials (for example, a bot token) in a context. This allows multiple subscribers within that workspace to receive notifications without each subscriber needing to store the shared token.
70
-
-**A/B Testing**: Pass a campaign identifier in a context (for example, campaign: 'new-welcome-email-v2'). Use this in a condition step to split users into different notification paths and measure which performs better.
71
-
-**Data Residency and Compliance**: Use a region context to tag notifications with their origin. This can help in applying data retention policies or filtering data for compliance audits.
68
+
-**Multi-tenancy and app routing**: Use a tenant or app context to dynamically alter notification content, branding, or logic for different customers or applications from a single workflow.
69
+
-**Shared chat credentials**: For chat providers like Slack or MS Teams, store workspace-level credentials (for example, a bot token) in a context. This allows multiple subscribers within that workspace to receive notifications without each subscriber needing to store the shared token.
70
+
-**A/B testing**: Pass a campaign identifier in a context (for example, campaign: 'new-welcome-email-v2'). Use this in a condition step to split users into different notification paths and measure which performs better.
71
+
-**Data residency and compliance**: Use a region context to tag notifications with their origin. This can help in applying data retention policies or filtering data for compliance audits.
72
72
73
-
## How to use Contexts
73
+
## How to use contexts
74
74
75
75
Once a context is created, you can access its properties anywhere variables are supported, such as in template editors or condition steps.
76
76
@@ -103,20 +103,45 @@ Once a context is created, you can access its properties anywhere variables are
103
103
Your account is on the {{context.tenant.data.plan}} plan.
104
104
```
105
105
106
-
* Using Context in Conditions
106
+
* Using context in step conditions
107
107
108
108
You can use context variables in the **Step conditions** tab of a workflow step to add conditional logic to your notifications. For example, only send a "Feature X is now enabled" email if `context.tenant.data.plan` is `enterprise`.
Once you start using contexts in your workflows, Novu provides full observability so you can monitor and debug your context usage after a workflow has been triggered.
114
+
115
+
### Searching for workflow runs
116
+
117
+
You can filter your workflow runs to find all executions associated with a specific context.
118
+
119
+
1. Navigate to the **Activity Feed** in your Novu dashboard.
120
+
2. Select the **Workflow Runs** tab.
121
+
3. In the search bar, click **Context** and enter the context `type` and `id` using the format `type:id`.
122
+
123
+

124
+
125
+
### Verifying the resolved context
126
+
127
+
To confirm that Novu received and processed your context data correctly, you can inspect the API traces for a specific run.
128
+
129
+
1. From the **Activity Feed**, select the relevant workflow run from the list in the **Requests** tab.
130
+
2. In the workflow run details, go to the **API Traces** tab.
131
+
132
+
Here, you will see the full context object that was resolved and attached to that specific workflow execution.
133
+
134
+

135
+
136
+
## Manage context
112
137
113
138
Novu provides two ways to manage contexts, either through the Novu dashboard or using the API.
114
139
115
-
### Creating a Context
140
+
### Create a Context
116
141
117
142
You can create a new context via Novu dashboard or API, when you want to register reusable metadata. After creation, this context becomes available to all workflows and templates within your environment.
118
143
119
-
#### Create a Context from the dashboard
144
+
#### Create a context via dashboard
120
145
121
146
Use the dashboard to manually define contexts that represent key business entities.
122
147
@@ -129,7 +154,7 @@ Use the dashboard to manually define contexts that represent key business entiti
129
154
-**Custom data (JSON)**: An optional JSON object that contains metadata, such as branding, plan, or region details.
130
155
5. Click **Create context** to save the context.
131
156
132
-
#### Create a Context using the API
157
+
#### Create a context via API
133
158
134
159
Novu provides an API to create a context. If a context with the same `type:id` combination already exists, then the request will fail.
135
160
@@ -145,7 +170,7 @@ POST /v2/contexts
145
170
}
146
171
```
147
172
148
-
#### Create a Context using the API (Just-in-time)
173
+
#### Create a context via API (Just-in-time)
149
174
150
175
Contexts can also be created automatically when you trigger a workflow that includes a new context object. If the specified `type:id` doesn’t exist, then Novu automatically creates it before running the workflow.
You can update a context’s data payload at any time. The context `type` and `id` remain immutable.
166
191
167
-
#### Update a Context from the dashboard
192
+
#### Update a context via dashboard
168
193
169
194
1. Log in to the Novu dashboard.
170
195
2. Click **Contexts** on the sidebar.
171
196
3. Click on the context you wish to edit from the context list on the Context page.
172
197
4. Modify its data object in the UI.
173
198
5. Click **Save changes**.
174
199
175
-
#### Update a Context using the API
200
+
#### Update a context via API
176
201
177
202
Novu provides an API to update an existing context. The `data` object is replaced entirely during updates (not merged). Include all fields you want to retain.
You can retrieve a context to verify its data, confirm its creation, or inspect the metadata it holds.
192
217
193
-
#### Retrieve a Context from the dashboard
218
+
#### Retrieve a context via dashboard
194
219
195
220
1. Log in to the Novu dashboard
196
221
2. Click **Contexts** on the sidebar to view the list of all existing contexts.
197
222
3. Click any context entry to see its details.
198
223
199
-
#### Retrieve a Context using the API
224
+
#### Retrieve a context via API
200
225
201
226
Novu provides an API to retrieve a single, specific context by providing its `type` and `id` in the URL.
202
227
@@ -209,17 +234,17 @@ Here is an example:
209
234
GET /v2/contexts/tenant/acme-corp
210
235
```
211
236
212
-
### Listing or searching for Contexts
237
+
### List or search for contexts
213
238
214
239
You can list all contexts in your environment or search for specific ones by context type or ID.
215
240
216
-
#### List or search Contexs from the dashboard
241
+
#### List or search for contexs via dashboard
217
242
218
243
1. Log in to the Novu dashboard
219
244
2. Click **Contexts** on the sidebar to view all contexts.
220
245
3. Use the search bar to filter by context type or ID.
221
246
222
-
#### List or search Contexs using the API
247
+
#### List or search for contexs via API
223
248
224
249
Novu provides an API that lists or searches available contexts. Use pagination and search parameters to retrieve subsets efficiently.
225
250
@@ -228,21 +253,21 @@ GET /v2/contexts
228
253
GET /v2/contexts?search=acme
229
254
```
230
255
231
-
### Deleting a Context
256
+
### Delete a context
232
257
233
258
Delete a context if it’s no longer needed. This action permanently removes the context from your Novu environment.
234
259
235
260
<Callouttype='warn'>This action cannot be undone, so ensure the context is no longer required by any active or historical workflows you might need to analyze.</Callout>
236
261
237
-
#### Delete a Context from the dashboard
262
+
#### Delete a context via dashboard
238
263
239
264
1. Log in to the Novu dashboard.
240
265
2. Click **Contexts** on the sidebar.
241
266
3. Click on the **...** icon on the row of the context you want to remove.
242
267
4. Click **Delete context**, a menu will appear.
243
268
5. Click **Delete context**.
244
269
245
-
#### Delete a Context using the API
270
+
#### Delete a context via API
246
271
247
272
Novu provides an API that you can use to delete a context. Once deleted, the context will no longer be available for use in new workflow executions.
0 commit comments