- 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
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.contexts.create(create_context_request_dto={
"type": "tenant",
"id": "org-acme",
"data": {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark",
},
},
})
# Handle response
print(res)| Parameter | Type | Required | Description |
|---|---|---|---|
create_context_request_dto |
models.CreateContextRequestDto | ✔️ | N/A |
idempotency_key |
Optional[str] | ➖ | A header for idempotency purposes |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
models.ContextsControllerCreateContextResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models.ErrorDto | 414 | application/json |
| models.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models.ValidationErrorDto | 422 | application/json |
| models.ErrorDto | 500 | application/json |
| models.APIError | 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
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.contexts.list(request={
"limit": 10,
"id": "tenant-prod-123",
"search": "tenant",
})
# Handle response
print(res)| Parameter | Type | Required | Description |
|---|---|---|---|
request |
models.ContextsControllerListContextsRequest | ✔️ | The request object to use for the request. |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
models.ContextsControllerListContextsResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models.ErrorDto | 414 | application/json |
| models.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models.ValidationErrorDto | 422 | application/json |
| models.ErrorDto | 500 | application/json |
| models.APIError | 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
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.contexts.update(id="<id>", type_="<value>", update_context_request_dto={
"data": {
"tenantName": "Acme Corp",
"region": "us-east-1",
"settings": {
"theme": "dark",
},
},
})
# Handle response
print(res)| Parameter | Type | Required | Description |
|---|---|---|---|
id |
str | ✔️ | Context ID |
type |
str | ✔️ | Context type |
update_context_request_dto |
models.UpdateContextRequestDto | ✔️ | N/A |
idempotency_key |
Optional[str] | ➖ | A header for idempotency purposes |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
models.ContextsControllerUpdateContextResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models.ErrorDto | 414 | application/json |
| models.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models.ValidationErrorDto | 422 | application/json |
| models.ErrorDto | 500 | application/json |
| models.APIError | 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
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.contexts.retrieve(id="<id>", type_="<value>")
# Handle response
print(res)| Parameter | Type | Required | Description |
|---|---|---|---|
id |
str | ✔️ | Context ID |
type |
str | ✔️ | Context type |
idempotency_key |
Optional[str] | ➖ | A header for idempotency purposes |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
models.ContextsControllerGetContextResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models.ErrorDto | 414 | application/json |
| models.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models.ValidationErrorDto | 422 | application/json |
| models.ErrorDto | 500 | application/json |
| models.APIError | 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
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.contexts.delete(id="<id>", type_="<value>")
# Handle response
print(res)| Parameter | Type | Required | Description |
|---|---|---|---|
id |
str | ✔️ | Context ID |
type |
str | ✔️ | Context type |
idempotency_key |
Optional[str] | ➖ | A header for idempotency purposes |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
models.ContextsControllerDeleteContextResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models.ErrorDto | 414 | application/json |
| models.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models.ValidationErrorDto | 422 | application/json |
| models.ErrorDto | 500 | application/json |
| models.APIError | 4XX, 5XX | */* |