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
 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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, overrides: RequestOverrides = None) -> ListResponse[Webhook]:
        """
        List all webhook destinations

        Args:
            overrides: The request overrides to apply to the request

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

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

        Parameters:
            webhook_id: The ID of the webhook destination to get
            overrides: The request overrides to apply to the request

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

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

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

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

    def update(
        self,
        webhook_id: str,
        request_body: UpdateWebhookRequest,
        overrides: RequestOverrides = None,
    ) -> 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
            overrides: The request overrides to apply to the request

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

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

        Parameters:
            webhook_id: The ID of the webhook destination to delete
            overrides: The request overrides to apply to the request

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

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

        Parameters:
            webhook_id: The ID of the webhook destination to update
            overrides: The request overrides to apply to the request

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

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

        Args:
            overrides: The request overrides to apply to the request

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

create(request_body, overrides=None)

Create a webhook destination

Parameters:

Name Type Description Default
request_body CreateWebhookRequest

The request body to create the webhook destination

required
overrides RequestOverrides

The request overrides to apply to the request

None

Returns:

Type Description
Response[WebhookWithSecret]

The created webhook destination

Source code in nylas/resources/webhooks.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def create(
    self, request_body: CreateWebhookRequest, overrides: RequestOverrides = None
) -> Response[WebhookWithSecret]:
    """
    Create a webhook destination

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

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

destroy(webhook_id, overrides=None)

Delete a webhook destination

Parameters:

Name Type Description Default
webhook_id str

The ID of the webhook destination to delete

required
overrides RequestOverrides

The request overrides to apply to the request

None

Returns:

Type Description
WebhookDeleteResponse

The response from deleting the webhook destination

Source code in nylas/resources/webhooks.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def destroy(
    self, webhook_id: str, overrides: RequestOverrides = None
) -> WebhookDeleteResponse:
    """
    Delete a webhook destination

    Parameters:
        webhook_id: The ID of the webhook destination to delete
        overrides: The request overrides to apply to the request

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

find(webhook_id, overrides=None)

Get a webhook destination

Parameters:

Name Type Description Default
webhook_id str

The ID of the webhook destination to get

required
overrides RequestOverrides

The request overrides to apply to the request

None

Returns:

Type Description
Response[Webhook]

The webhook destination

Source code in nylas/resources/webhooks.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def find(
    self, webhook_id: str, overrides: RequestOverrides = None
) -> Response[Webhook]:
    """
    Get a webhook destination

    Parameters:
        webhook_id: The ID of the webhook destination to get
        overrides: The request overrides to apply to the request

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

ip_addresses(overrides=None)

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

Parameters:

Name Type Description Default
overrides RequestOverrides

The request overrides to apply to the request

None

Returns:

Type Description
Response[WebhookIpAddressesResponse]

The list of IP addresses that Nylas sends webhooks from

Source code in nylas/resources/webhooks.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
def ip_addresses(
    self, overrides: RequestOverrides = None
) -> Response[WebhookIpAddressesResponse]:
    """
    Get the current list of IP addresses that Nylas sends webhooks from

    Args:
        overrides: The request overrides to apply to the request

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

list(overrides=None)

List all webhook destinations

Parameters:

Name Type Description Default
overrides RequestOverrides

The request overrides to apply to the request

None

Returns:

Type Description
ListResponse[Webhook]

The list of webhook destinations

Source code in nylas/resources/webhooks.py
35
36
37
38
39
40
41
42
43
44
45
def list(self, overrides: RequestOverrides = None) -> ListResponse[Webhook]:
    """
    List all webhook destinations

    Args:
        overrides: The request overrides to apply to the request

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

rotate_secret(webhook_id, overrides=None)

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
overrides RequestOverrides

The request overrides to apply to the request

None

Returns:

Type Description
Response[WebhookWithSecret]

The updated webhook destination

Source code in nylas/resources/webhooks.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def rotate_secret(
    self, webhook_id: str, overrides: RequestOverrides = None
) -> Response[WebhookWithSecret]:
    """
    Update the webhook secret value for a destination

    Parameters:
        webhook_id: The ID of the webhook destination to update
        overrides: The request overrides to apply to the request

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

update(webhook_id, request_body, overrides=None)

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
overrides RequestOverrides

The request overrides to apply to the request

None

Returns:

Type Description
Response[Webhook]

The updated webhook destination

Source code in nylas/resources/webhooks.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def update(
    self,
    webhook_id: str,
    request_body: UpdateWebhookRequest,
    overrides: RequestOverrides = None,
) -> 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
        overrides: The request overrides to apply to the request

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

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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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]