Skip to content

webhooks

Webhooks

Bases: ListableApiResource, FindableApiResource, CreatableApiResource, UpdatableApiResource, DestroyableApiResource

Nylas Webhooks API

The Nylas webhooks API allows you to manage webhook destinations for your Nylas application.

Source code in nylas/resources/webhooks.py
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
class Webhooks(
    ListableApiResource,
    FindableApiResource,
    CreatableApiResource,
    UpdatableApiResource,
    DestroyableApiResource,
):
    """
    Nylas Webhooks API

    The Nylas webhooks API allows you to manage webhook destinations for your Nylas application.
    """

    def list(self) -> ListResponse[Webhook]:
        """
        List all webhook destinations

        Returns:
            The list of webhook destinations
        """
        return super().list(path="/v3/webhooks", response_type=Webhook)

    def find(self, webhook_id: str) -> Response[Webhook]:
        """
        Get a webhook destination

        Parameters:
            webhook_id: The ID of the webhook destination to get

        Returns:
            The webhook destination
        """
        return super().find(path=f"/v3/webhooks/{webhook_id}", response_type=Webhook)

    def create(self, request_body: CreateWebhookRequest) -> Response[WebhookWithSecret]:
        """
        Create a webhook destination

        Parameters:
            request_body: The request body to create the webhook destination

        Returns:
            The created webhook destination
        """
        return super().create(
            path="/v3/webhooks",
            request_body=request_body,
            response_type=WebhookWithSecret,
        )

    def update(
        self, webhook_id: str, request_body: UpdateWebhookRequest
    ) -> Response[Webhook]:
        """
        Update a webhook destination

        Parameters:
            webhook_id: The ID of the webhook destination to update
            request_body: The request body to update the webhook destination

        Returns:
            The updated webhook destination
        """
        return super().update(
            path=f"/v3/webhooks/{webhook_id}",
            request_body=request_body,
            response_type=Webhook,
        )

    def destroy(self, webhook_id: str) -> WebhookDeleteResponse:
        """
        Delete a webhook destination

        Parameters:
            webhook_id: The ID of the webhook destination to delete

        Returns:
            The response from deleting the webhook destination
        """
        return super().destroy(
            path=f"/v3/webhooks/{webhook_id}", response_type=WebhookDeleteResponse
        )

    def rotate_secret(self, webhook_id: str) -> Response[WebhookWithSecret]:
        """
        Update the webhook secret value for a destination

        Parameters:
            webhook_id: The ID of the webhook destination to update

        Returns:
            The updated webhook destination
        """
        res = self._http_client._execute(
            method="PUT",
            path=f"/v3/webhooks/{webhook_id}/rotate-secret",
            request_body={},
        )
        return Response.from_dict(res, WebhookWithSecret)

    def ip_addresses(self) -> Response[WebhookIpAddressesResponse]:
        """
        Get the current list of IP addresses that Nylas sends webhooks from

        Returns:
            The list of IP addresses that Nylas sends webhooks from
        """
        res = self._http_client._execute(method="GET", path="/v3/webhooks/ip-addresses")
        return Response.from_dict(res, WebhookIpAddressesResponse)

create(request_body)

Create a webhook destination

Parameters:

Name Type Description Default
request_body CreateWebhookRequest

The request body to create the webhook destination

required

Returns:

Type Description
Response[WebhookWithSecret]

The created webhook destination

Source code in nylas/resources/webhooks.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def create(self, request_body: CreateWebhookRequest) -> Response[WebhookWithSecret]:
    """
    Create a webhook destination

    Parameters:
        request_body: The request body to create the webhook destination

    Returns:
        The created webhook destination
    """
    return super().create(
        path="/v3/webhooks",
        request_body=request_body,
        response_type=WebhookWithSecret,
    )

destroy(webhook_id)

Delete a webhook destination

Parameters:

Name Type Description Default
webhook_id str

The ID of the webhook destination to delete

required

Returns:

Type Description
WebhookDeleteResponse

The response from deleting the webhook destination

Source code in nylas/resources/webhooks.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def destroy(self, webhook_id: str) -> WebhookDeleteResponse:
    """
    Delete a webhook destination

    Parameters:
        webhook_id: The ID of the webhook destination to delete

    Returns:
        The response from deleting the webhook destination
    """
    return super().destroy(
        path=f"/v3/webhooks/{webhook_id}", response_type=WebhookDeleteResponse
    )

find(webhook_id)

Get a webhook destination

Parameters:

Name Type Description Default
webhook_id str

The ID of the webhook destination to get

required

Returns:

Type Description
Response[Webhook]

The webhook destination

Source code in nylas/resources/webhooks.py
43
44
45
46
47
48
49
50
51
52
53
def find(self, webhook_id: str) -> Response[Webhook]:
    """
    Get a webhook destination

    Parameters:
        webhook_id: The ID of the webhook destination to get

    Returns:
        The webhook destination
    """
    return super().find(path=f"/v3/webhooks/{webhook_id}", response_type=Webhook)

ip_addresses()

Get the current list of IP addresses that Nylas sends webhooks from

Returns:

Type Description
Response[WebhookIpAddressesResponse]

The list of IP addresses that Nylas sends webhooks from

Source code in nylas/resources/webhooks.py
121
122
123
124
125
126
127
128
129
def ip_addresses(self) -> Response[WebhookIpAddressesResponse]:
    """
    Get the current list of IP addresses that Nylas sends webhooks from

    Returns:
        The list of IP addresses that Nylas sends webhooks from
    """
    res = self._http_client._execute(method="GET", path="/v3/webhooks/ip-addresses")
    return Response.from_dict(res, WebhookIpAddressesResponse)

list()

List all webhook destinations

Returns:

Type Description
ListResponse[Webhook]

The list of webhook destinations

Source code in nylas/resources/webhooks.py
34
35
36
37
38
39
40
41
def list(self) -> ListResponse[Webhook]:
    """
    List all webhook destinations

    Returns:
        The list of webhook destinations
    """
    return super().list(path="/v3/webhooks", response_type=Webhook)

rotate_secret(webhook_id)

Update the webhook secret value for a destination

Parameters:

Name Type Description Default
webhook_id str

The ID of the webhook destination to update

required

Returns:

Type Description
Response[WebhookWithSecret]

The updated webhook destination

Source code in nylas/resources/webhooks.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def rotate_secret(self, webhook_id: str) -> Response[WebhookWithSecret]:
    """
    Update the webhook secret value for a destination

    Parameters:
        webhook_id: The ID of the webhook destination to update

    Returns:
        The updated webhook destination
    """
    res = self._http_client._execute(
        method="PUT",
        path=f"/v3/webhooks/{webhook_id}/rotate-secret",
        request_body={},
    )
    return Response.from_dict(res, WebhookWithSecret)

update(webhook_id, request_body)

Update a webhook destination

Parameters:

Name Type Description Default
webhook_id str

The ID of the webhook destination to update

required
request_body UpdateWebhookRequest

The request body to update the webhook destination

required

Returns:

Type Description
Response[Webhook]

The updated webhook destination

Source code in nylas/resources/webhooks.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def update(
    self, webhook_id: str, request_body: UpdateWebhookRequest
) -> Response[Webhook]:
    """
    Update a webhook destination

    Parameters:
        webhook_id: The ID of the webhook destination to update
        request_body: The request body to update the webhook destination

    Returns:
        The updated webhook destination
    """
    return super().update(
        path=f"/v3/webhooks/{webhook_id}",
        request_body=request_body,
        response_type=Webhook,
    )

extract_challenge_parameter(url)

Extract the challenge parameter from a URL

Parameters:

Name Type Description Default
url str

The URL sent by Nylas containing the challenge parameter

required

Returns:

Type Description
str

The challenge parameter

Source code in nylas/resources/webhooks.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def extract_challenge_parameter(url: str) -> str:
    """
    Extract the challenge parameter from a URL

    Parameters:
        url: The URL sent by Nylas containing the challenge parameter

    Returns:
        The challenge parameter
    """
    url_object = urllib.parse.urlparse(url)
    query = urllib.parse.parse_qs(url_object.query)
    challenge_parameter = query.get("challenge")
    if not challenge_parameter:
        raise ValueError("Invalid URL or no challenge parameter found.")

    return challenge_parameter[0]