Webhook Management

generate_webhook_secret

Generates a webhook secret from a secure random source.

Arguments

None

Return

Base64-decoded string of the generated webhook secret.

HCK7CWdt83qYfstai9eRlu1Sbw3cZ1uQ1kQYcgofW/Q=

Examples

from datature.nexus.utils import utils

utils.generate_webhook_secret()

create

Creates a webhook to a public HTTPs URL.

Arguments

AttributeTypeDescription
namestrName of the webhook.
webhook_specWebhookSpecWebhook configuration.

Return

🚧

For security purposes, webhook secrets will NOT be returned in the response body. Please use the test() function to validate that our servers can establish a connection with your endpoint URL.

WebhookModel object containing the metadata of the newly-created webhook with the following structure:

WebhookModel(
    id='webhook_f7d8aec2-7e2b-4d2c-a103-c8dd575c29c7',
    object='webhook',
    project_id='proj_ca5fe71e7592bbcf7705ea36e4f29ed4',
    name='aws-lambda',
    endpoint='https://lambda-url.ap-southeast-1.on.aws/',
    retries=WebhookRetries(
        max_retries=3,
        max_retry_delay=15000
    ),
    create_date=1723633671620,
    update_date=1723736909980
)
AttributeTypeDescription
idstrThe webhook ID as a string.
objectstrObject type of the webhook.
project_idstrIdentifier of the project associated with the webhook.
namestrName of the webhook.
endpointstrURL endpoint of the webhook.
retriesWebhookRetriesRetry configuration for the webhook.
create_dateintCreation timestamp of the webhook, in milliseconds.
update_dateintLast updated timestamp of the webhook, in milliseconds.

Examples

Create a new webhook with a generated webhook secret:

from datature.nexus import Client
from datature.nexus.utils import utils
project = Client("5aa41e8ba........").get_project("proj_b705a........")

webhook_secret = utils.generate_webhook_secret()

project.batch.webhooks.create(
    name="aws-lambda",
    webhook_spec={
        "endpoint": "https://lambda-url.ap-southeast-1.on.aws/",
        "retries": {
            "max_retries": 3,
            "max_retry_delay": 15000
        },
        "secret": {
            "contents": webhook_secret,
        },
    }
)

list

Lists all created webhooks in the project.

Arguments

NameTypeDescription
paginationdictA dictionary containing the limit of the number of webhooks to be returned in each page (defaults to 1000), and the page cursor for page selection (defaults to the first page)

Return

PaginationResponse object containing a list of WebhookModel objects with page navigation data, with the following structure:

PaginationResponse(
    next_page=None,
    prev_page=None,
    data=[
        WebhookModel(
            id='webhook_f7d8aec2-7e2b-4d2c-a103-c8dd575c29c7',
            object='webhook',
            project_id='proj_ca5fe71e7592bbcf7705ea36e4f29ed4',
            name='localhost',
            endpoint='https://lambda-url.ap-southeast-1.on.aws/',
            retries=WebhookRetries(
                max_retries=3,
                max_retry_delay=15000
            ),
            create_date=1723633671620,
            update_date=1723736909980
        )
    ]
)
AttributeTypeDescription
next_pagestrPage ID of the next page.
prev_pagestrPage ID of the prev page.
dataList[WebhookModel]List of webhook metadata.

Examples

  • Default listing of webhooks (shows first 1000 webhooks):
from datature.nexus import Client

project = Client("5aa41e8ba........").get_project("proj_b705a........")

project.batch.webhooks.list()
  • View the next page of results:
from datature.nexus import Client

project = Client("5aa41e8ba........").get_project("proj_b705a........")

next_page = project.batch.webhooks.list()["next_page"]

project.batch.webhooks.list({"page": next_page})
  • View the previous page of results:
from datature.nexus import Client

project = Client("5aa41e8ba........").get_project("proj_b705a........")

prev_page = project.batch.webhooks.list({
    "page": "ZjYzYmJkM2FjN2UxOTA4ZmU0ZjE0Yjk5Mg"}
)["prev_page"]

project.batch.webhooks.list({"page": prev_page})
  • List a specific page of webhooks that returns 2 webhooks on that page:
from datature.nexus import Client
  
project = Client("5aa41e8ba........").get_project("proj_b705a........")

project.batch.webhooks.list({
    "limit": 2,
    "page": "ZjYzYmJkM2FjN2UxOTA4ZmU0ZjE0Yjk5Mg"
})

get

Retrieves a specific webhook by ID.

Arguments

NameTypeDescription
webhook_idstrThe webhook ID as a string.

Return

WebhookModel object containing the metadata of the retrieved webhook with the following structure:

WebhookModel(
    id='webhook_f7d8aec2-7e2b-4d2c-a103-c8dd575c29c7',
    object='webhook',
    project_id='proj_ca5fe71e7592bbcf7705ea36e4f29ed4',
    name='aws-lambda',
    endpoint='https://lambda-url.ap-southeast-1.on.aws/',
    retries=WebhookRetries(
        max_retries=3,
        max_retry_delay=15000
    ),
    create_date=1723633671620,
    update_date=1723736909980
)
AttributeTypeDescription
idstrThe webhook ID as a string.
objectstrObject type of the webhook.
project_idstrIdentifier of the project associated with the webhook.
namestrName of the webhook.
endpointstrURL endpoint of the webhook.
retriesWebhookRetriesRetry configuration for the webhook.
create_dateintCreation timestamp of the webhook, in milliseconds.
update_dateintLast updated timestamp of the webhook, in milliseconds.

Examples

Retrieve webhook by webhook ID:

from datature.nexus import Client

project = Client("5aa41e8ba........").get_project("proj_b705a........")
project.batch.webhooks.get("webhook_6aea3395-9a72-4bb5-9ee0-19248c903c56")

update

Updates the configuration of a specific webhook. All webhook fields can be updated, with the exception of the webhook secret, which can only be updated through the update_secret() function.

Arguments

NameTypeDescription
webhook_idstrThe webhook ID as a string.
webhook_specstrNew webhook configuration.

Return

WebhookModel object containing the metadata of the newly-created webhook with the following structure:

WebhookModel(
    id='webhook_f7d8aec2-7e2b-4d2c-a103-c8dd575c29c7',
    object='webhook',
    project_id='proj_ca5fe71e7592bbcf7705ea36e4f29ed4',
    name='aws-lambda',
    endpoint='https://lambda-url.ap-southeast-1.on.aws/',
    retries=WebhookRetries(
        max_retries=3,
        max_retry_delay=15000
    ),
    create_date=1723633671620,
    update_date=1723736909980
)
AttributeTypeDescription
idstrThe webhook ID as a string.
objectstrObject type of the webhook.
project_idstrIdentifier of the project associated with the webhook.
namestrName of the webhook.
endpointstrURL endpoint of the webhook.
retriesWebhookRetriesRetry configuration for the webhook.
create_dateintCreation timestamp of the webhook, in milliseconds.
update_dateintLast updated timestamp of the webhook, in milliseconds.

Examples

Update the endpoint and retry configuration of an existing webhook:

from datature.nexus import Client
project = Client("5aa41e8ba........").get_project("proj_b705a........")

project.batch.webhooks.update(
    webhook_id="webhook_f7d8aec2-7e2b-4d2c-a103-c8dd575c29c7",
    webhook_spec={
        "endpoint": "https://lambda-url.ap-southeast-1.on.aws/",
        "retries": {
            "max_retries": 3,
            "max_retry_delay": 15000
        }
    }
)

update_secret

Updates the webhook secret of a specific webhook by ID.

Arguments

NameTypeDescription
webhook_idstrThe webhook ID as a string.
secretstrThe new base64-decoded webhook secret.

Return

🚧

For security purposes, webhook secrets will NOT be returned in the response body. Please use the test() function to validate that our servers can establish a connection with your endpoint URL.

WebhookModel object containing the metadata of the newly-created webhook with the following structure:

WebhookModel(
    id='webhook_f7d8aec2-7e2b-4d2c-a103-c8dd575c29c7',
    object='webhook',
    project_id='proj_ca5fe71e7592bbcf7705ea36e4f29ed4',
    name='aws-lambda',
    endpoint='https://lambda-url.ap-southeast-1.on.aws/',
    retries=WebhookRetries(
        max_retries=3,
        max_retry_delay=15000
    ),
    create_date=1723633671620,
    update_date=1723736909980
)
AttributeTypeDescription
idstrThe webhook ID as a string.
objectstrObject type of the webhook.
project_idstrIdentifier of the project associated with the webhook.
namestrName of the webhook.
endpointstrURL endpoint of the webhook.
retriesWebhookRetriesRetry configuration for the webhook.
create_dateintCreation timestamp of the webhook, in milliseconds.
update_dateintLast updated timestamp of the webhook, in milliseconds.

Examples

Generate a new webhook secret and update an existing webhook:

from datature.nexus import Client
from datature.nexus.utils import utils
project = Client("5aa41e8ba........").get_project("proj_b705a........")

webhook_secret = utils.generate_webhook_secret()

project.batch.webhooks.update_secret(
    webhook_id="webhook_f7d8aec2-7e2b-4d2c-a103-c8dd575c29c7",
    secret=webhook_secret,
)

test

Tests a webhook by sending a sample payload to the endpoint URL.

Arguments

NameTypeDescription
webhook_idstrThe webhook ID as a string.

Return

WebhookTestResponse object containing details of the webhook test with the following structure:

WebhookTestResponse(
    status='Ok',
    response_code=204,
    latency_ms=648,
    attempt_count=1,
    body=None,
    reason=None
)
AttributeTypeDescription
statusstrStatus of the webhook test
response_codeintResponse code of the webhook test.
latency_msintLatency of the webhook test, in milliseconds.
attempt_countintNumber of attempts made to test the webhook for a successful response.
bodyOptional[str]Body of the webhook test response, if any.
reasonOptional[str]Reason for the error in the webhook test response, if any.

Examples

Send a sample payload to the specified webhook:

from datature.nexus import Client
project = Client("5aa41e8ba........").get_project("proj_b705a........")

project.batch.webhooks.test("webhook_f7d8aec2-7e2b-4d2c-a103-c8dd575c29c7")

delete

Deletes a specific webhook by ID.

Arguments

NameTypeDescription
webhook_idstrThe webhook ID as a string.

Return

DeleteResponse object that describe the deletion status of the webhook, with the following structure:

DeleteResponse(
    id='webhook_f7d8aec2-7e2b-4d2c-a103-c8dd575c29c7',
    deleted=True
)
AttributeTypeDescription
idstrThe webhook ID as a string.
deletedboolWhether the webhook has been successfully deleted or not.

Examples

Delete a specified webhook:

from datature.nexus import Client
project = Client("5aa41e8ba........").get_project("proj_b705a........")

project.batch.webhooks.delete("webhook_f7d8aec2-7e2b-4d2c-a103-c8dd575c29c7")