Skip to content

Latest commit

 

History

History
266 lines (186 loc) · 17.2 KB

File metadata and controls

266 lines (186 loc) · 17.2 KB

Contexts

Overview

Available Operations

create

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

Example Usage

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)

Parameters

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.

Response

models.ContextsControllerCreateContextResponse

Errors

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 */*

list

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

Example Usage

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)

Parameters

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.

Response

models.ContextsControllerListContextsResponse

Errors

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

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

Example Usage

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)

Parameters

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.

Response

models.ContextsControllerUpdateContextResponse

Errors

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

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

Example Usage

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)

Parameters

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.

Response

models.ContextsControllerGetContextResponse

Errors

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

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

Example Usage

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)

Parameters

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.

Response

models.ContextsControllerDeleteContextResponse

Errors

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 */*