- create - Create a context
- list - List all contexts
- update - Update a context
- retrieve - Retrieve a context
- delete - Delete a context
Create a new context with the specified type, id, and data. Returns 409 if context already exists. type and id are required fields, data is optional, if the context already exists, it returns the 409 response
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.contexts.create({
type: "tenant",
id: "org-acme",
data: {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark",
},
},
});
console.log(result);
}
run();The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { contextsCreate } from "@novu/api/funcs/contextsCreate.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const res = await contextsCreate(novu, {
type: "tenant",
id: "org-acme",
data: {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark",
},
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("contextsCreate failed:", res.error);
}
}
run();| Parameter | Type | Required | Description |
|---|---|---|---|
createContextRequestDto |
components.CreateContextRequestDto | ✔️ | N/A |
idempotencyKey |
string | ➖ | A header for idempotency purposes |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.ContextsControllerCreateContextResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.ErrorDto | 414 | application/json |
| errors.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| errors.ValidationErrorDto | 422 | application/json |
| errors.ErrorDto | 500 | application/json |
| errors.SDKError | 4XX, 5XX | */* |
Retrieve a paginated list of all contexts, optionally filtered by type and key pattern. type and id are optional fields, if provided, only contexts with the matching type and id will be returned. search is an optional field, if provided, only contexts with the matching key pattern will be returned. Checkout all possible parameters in the query section below for more details
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.contexts.list({
limit: 10,
id: "tenant-prod-123",
search: "tenant",
});
console.log(result);
}
run();The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { contextsList } from "@novu/api/funcs/contextsList.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const res = await contextsList(novu, {
limit: 10,
id: "tenant-prod-123",
search: "tenant",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("contextsList failed:", res.error);
}
}
run();| Parameter | Type | Required | Description |
|---|---|---|---|
request |
operations.ContextsControllerListContextsRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.ContextsControllerListContextsResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.ErrorDto | 414 | application/json |
| errors.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| errors.ValidationErrorDto | 422 | application/json |
| errors.ErrorDto | 500 | application/json |
| errors.SDKError | 4XX, 5XX | */* |
Update the data of an existing context. type and id are required fields, data is required. Only the data field is updated, the rest of the context is not affected. If the context does not exist, it returns the 404 response
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.contexts.update({
id: "<id>",
type: "<value>",
updateContextRequestDto: {
data: {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark",
},
},
},
});
console.log(result);
}
run();The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { contextsUpdate } from "@novu/api/funcs/contextsUpdate.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const res = await contextsUpdate(novu, {
id: "<id>",
type: "<value>",
updateContextRequestDto: {
data: {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark",
},
},
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("contextsUpdate failed:", res.error);
}
}
run();| Parameter | Type | Required | Description |
|---|---|---|---|
request |
operations.ContextsControllerUpdateContextRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.ContextsControllerUpdateContextResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.ErrorDto | 414 | application/json |
| errors.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| errors.ValidationErrorDto | 422 | application/json |
| errors.ErrorDto | 500 | application/json |
| errors.SDKError | 4XX, 5XX | */* |
Retrieve a specific context by its type and id. type and id are required fields, if the context does not exist, it returns the 404 response
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.contexts.retrieve("<id>", "<value>");
console.log(result);
}
run();The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { contextsRetrieve } from "@novu/api/funcs/contextsRetrieve.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const res = await contextsRetrieve(novu, "<id>", "<value>");
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("contextsRetrieve failed:", res.error);
}
}
run();| Parameter | Type | Required | Description |
|---|---|---|---|
id |
string | ✔️ | Context ID |
type |
string | ✔️ | Context type |
idempotencyKey |
string | ➖ | A header for idempotency purposes |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.ContextsControllerGetContextResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.ErrorDto | 414 | application/json |
| errors.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| errors.ValidationErrorDto | 422 | application/json |
| errors.ErrorDto | 500 | application/json |
| errors.SDKError | 4XX, 5XX | */* |
Delete a context by its type and id. type and id are required fields, if the context does not exist, it returns the 404 response
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.contexts.delete("<id>", "<value>");
console.log(result);
}
run();The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { contextsDelete } from "@novu/api/funcs/contextsDelete.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const res = await contextsDelete(novu, "<id>", "<value>");
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("contextsDelete failed:", res.error);
}
}
run();| Parameter | Type | Required | Description |
|---|---|---|---|
id |
string | ✔️ | Context ID |
type |
string | ✔️ | Context type |
idempotencyKey |
string | ➖ | A header for idempotency purposes |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.ContextsControllerDeleteContextResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.ErrorDto | 414 | application/json |
| errors.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| errors.ValidationErrorDto | 422 | application/json |
| errors.ErrorDto | 500 | application/json |
| errors.SDKError | 4XX, 5XX | */* |