Only show these results:

Webhooks

Webhooks allow your application to receive notifications when certain events occur. For example, when a new email is received, Nylas will make a POST request to your callback_url endpoint, letting you know about the new message. You can specify what events you'd like to be notified about in the developer dashboard or with the Webhooks API.

Webhooks are the recommended way to get notified of changes to the accounts you sync because they can easily integrate with your app and scale seamlessly with your growth.

Prerequisites

To start using webhooks, you need:

Webhook Starters

Check out the Node.js, Ruby, Python ,and Java example projects to see how to start accepting notifications from Nylas.

How Webhooks Work with Nylas

Webhook Diagram Nylas

Let's go over a general workflow for using webhooks.

The first time you create a webhook or set the state to active, Nylas will check that the webhook is valid by a GET request to your endpoint with a challenge query parameter. Your application must return the exact value of the challenge query parameter in the body of the response.

If you fail to return a response within 10 seconds, Nylas will return a 400 BAD REQUEST. Nylas will not attempt to verify the webhook again.

Once you have your webhooks created, Nylas will send updates to your app, and you must respond with a 200 response. If you don't, Nylas will attempt 5 more times before changing the status to failing.

Every request from Nylas includes an X-Nylas-Signature header. You can use this to verify that the data is coming from Nylas.

Authorization

Webhooks use Basic Authentication. Use the application client_secret.

Authorization Example

Nylas Python Webhook App

        is_genuine = verify_signature(
message=request.data,
key=app.config["NYLAS_OAUTH_CLIENT_SECRET"].encode("utf8"),
signature=request.headers.get("X-Nylas-Signature"),
)
if not is_genuine:
return "Signature verification failed!", 401

Challenge Parameter

Anytime you create a webhook or set the state to active, Nylas will check to ensure your webhook is valid by making a GET request to your endpoint with a challenge query parameter. Your application needs to return the exact value of the challenge query parameter in the response body.

  • Your application has up to 10 seconds to respond to the verification request. The verification request is not retried if it fails the first check.
    • If your application does not respond to the verification, Nylas returns a 400 BAD REQUEST error.
  • Ensure you are not returning anything other than the challenge parameter's exact value, not even quotation marks.
    • Do not use chunked encoding in response to the GET.

Responding to Webhooks

You can respond to webhooks using 200-299 response codes.

Verification Request

Each request made by Nylas includes an X-Nylas-Signature header. The header contains a hex-encoded HMAC-SHA256 signature of the request body, using your client secret as the signing key. Using the header allows your application to verify that the notification came from Nylas.

The signature is for the exact content of the request body. Make sure that your processing code does not modify the body before checking the signature.

The body of the request is in the UTF-8 JSON format and contains details about the event.

Create Webhooks

Webhooks for an application are configured either from the Nylas Developer Dashboard or programmatically via a POST request to the webhooks endpoint.

Nylas Dashboard

To configure a new webhook using the dashboard, go to the Webhooks section of your application and select the webhooks you want to add.

You will need to provide:

  • The full callback_url for the webhook. The callback_url is the endpoint the Nylas servers send notifications to. The callback_url must be accessible from the public internet for the webhook to work. It must be an HTTPS endpoint as well. The endpoint is verified by sending a verification request.
  • The notification triggers. To see triggers response examples and definitions, review Available Webhooks.

API

To enable a webhook using the API, send a POST to https://api.nylas.com/a/{client_id}/webhooks.

You will need to provide:

  • The full callback_url for the webhook. The callback_url is the endpoint the Nylas servers send notifications to. The callback_url must be accessible from the public internet for the webhook to work. It must be an HTTPS endpoint as well. The endpoint is verified by sending a verification request.
  • The [notification triggers}(#notification-triggers). To see a triggers response examples and definitions, review Available Webhooks.
    • Basic Authentication where the username is the client_secret.
    POST /a/>cliient_id>/webhooks HTTP/1.1
Host: api.nylas.com
Authorization: Basic <client_secret>
Content-Type: application/json

{
"callback_url": "https://084eb929.ngrok.io/webook",
"triggers": [
"message.opened",
"contact.created"
],
"state": "active"
}

Notification Triggers

Trigger Description
account.connected An account has been connected to your app.
account.invalid An account has invalid credentials and must re-authenticate.
account.running An account is syncing and running properly.
account.stopped An account was stopped or cancelled.
account.sync_error An account has a sync error and is no longer syncing.
message.created A new message was sent or received.
message.link_clicked A link in a tracked message has been clicked by a message participant. Enable using Message Tracking.
message.opened A tracked message has been opened by a message participant. Enable using Message Tracking.
thread.replied A participant replied to a tracked thread.
contact.created A contact has been added to an account.
contact.updated A contact has been updated on an account.
contact.deleted A contact has been deleted from an account.
calendar.created A calendar has been added to an account.
calendar.updated A calendar has been updated on an account.
calendar.deleted A calendar has been deleted from an account.
event.created An event has been added to an account.
event.updated An event has been updated on an account. This can include event changes and event deletions.
event.deleted An event has been deleted from an account.
job.successful Job was successfully synced back to the provider for a given job_status_id.
job.failed The job has permanently failed after retrying 20 times. The changes have not synced with the provider.

Event Update and Delete

When events are canceled or deleted from a calendar, we send an event.updated webhook. Event deleted webhooks are only sent when a synback request fails. A failure can take a long time to come through. We recommend you use the event.updated webhook.

Email Tracking Notifications

If you have message tracking enabled, you may get 2 notifications for opened messages.

Newly Connected Accounts

When a new account is connected, Nylas will send webhook notifications for historical messages, calendars, events, and contacts as it syncs the account data.

Retry Attempts

Nylas will retry failed webhook messages up to 5 times, backing off exponentially. We guarantee that we will make at least 4 retries within the first 20 minutes, and all 5 retries will occur within 1 hour. If we cannot make a successful POST request to your endpoint after 5 retries, we will skip that message and continue to send other webhook notifications.

Failed Webhooks

A webhook is marked as failing when:

  • We have received 95% non-200 responses over a period of 15 minutes.
  • We have received no response from the endpoint over a period of 15 minutes.

When this happens, we send an email notifying you of the failing webhook and change the webhook's state in our database to failing.

A webhook is marked as failed when:

  • We have received 95% non-200 responses (or non-responses) from the endpoint over a period of 3 days.
  • We have received no response from the endpoint over a period of 3 days.

You can reactivate through the Nylas dashboard or by using the webhook endpoint.

Reactivated Failed Webhooks

When a failed webhook is reactivated, it will send notifications for events from that point in time forward. It will not send notifications for any events that occurred while it was in the failed state. If your webhook reaches the failed state, you can reactivate it from the developer console.

Notification Format

Nylas sends out payloads that contain the details of a single change. For security reasons, payloads don't include the details of the change, but instead, have the trigger type and object ID for each change. You can use this data to query the appropriate Nylas API endpoint to get the object's details

Message Created Format Example

    {
"deltas": [
{
"date": 1601654025,
"object": "message",
"type": "message.created",
"object_data": {
"namespace_id": "aaz875kwuvxik6ku7pwkqp3ah",
"account_id": "aaz875kwuvxik6ku7pwkqp3ah",
"object": "message",
"attributes": {
"thread_id": "52yua3vyqlu8qzxptl60rfyd9",
"received_date": 1601654026
},
"id": "67il0blaili658hdc6u1zt80w",
"metadata": null
}
}
]
}

Message Tracking

Use message tracking to get webhooks when a message is :

  • Opened
  • Replied to
  • Link is clicked

Read more about Message Tracking.

Enable and Disable Webhooks

Webhooks are set to active by default. To disable a webhook, go to the Webhooks section of your application and change the webhook's state to inactive. You can also make a PUT request to /webhook/{id} to set the state.

When you pause a webhook, it stops sending all events. When you reactive the webhook, all paused, webhooks are sent.

If you need to modify the callback_url or triggers for your webhook, please make a new POST request.

Whitelist IP Addresses

If you need to whitelist IP address, the IP Addresses endpoint returns a list of dynamic IP addresses.

Multiple Webhooks

You can create more than one webhook for your application, but the webhook endpoints can not be the same. For example, you may create a webhook to receive notifications for the message.created trigger, and another to receive notifications for the account.connected and account.stopped triggers, but the webhooks must have different callback URIs.

Historical Webhooks

Nylas lets you control which historical data triggers to send. Control messages, threads, calendar events, and contacts.

How Historical Webhooks Work

Webhooks are sent and controlled at the application level. This means any accounts you connect to your application will send webhooks. By default, when you connect an account, Nylas will send webhooks for data from and after the account connection date.

Using the Historical Webhooks settings, you can set a period to start receiving webhooks. There are 4 options.

  • Webhooks for data X days before account connection
  • Webhooks starting at account connection
  • Webhooks X days after account connection
  • Receive webhooks for all data

If you don't make any changes, the default setting is 0. Any newly connected accounts will only send data after the account is connected.

Existing Customers Historical Webhooks

If you already have an account set up with webhooks the behavior will not change. You will still continue to receive all webhooks.

Historical Webhooks Settings

Log in to your dashboard, choose the application you want to setup webhooks for, then click App Settings. On Settings, go to Application Product Settings and set the Number of days from account connection to send webhooks.

  • If you want webhooks 30 days before account connection, enter -30.
  • If you want webhooks starting from account connection, enter 0.
  • If you want webhooks 30 days after account connection, enter 30.
  • If you leave it blank, you will receive all hooks for all previous and new data.
Historical Webhooks Dashboard

Supported Objects

Object Sync Basis
Messages Received date
Thread Most recent received date. Threads can be incomplete if the sync date is not far enough in the past. Make sure to sync to the start of the threads.
Event Non-recurring events only. Uses event end time, if the event end time is not available, uses the event start time.
Contacts Contacts that have been automatically created from an email will sync from the message received date. All other contacts have no restrictions for historical webhooks and you will still receive hooks for them, regardless of dashboard settings.

Keep in Mind

  • Threads can be incomplete if the sync date is not far enough in the past. Make sure to sync to the start of the threads.
  • Historical Webhook settings only apply to new applications.
  • You should configure your webhook settings before adding accounts.
  • Webhook settings only apply to accounts connected after the settings are changed.

Best Practices

Use these suggestions to get the best experience using webhooks.

Asynchronous Processing

We strongly recommend processing webhook data asynchronously from ingested Nylas POST requests to avoid timeouts. Each request automatically times out after 10 seconds.

Enable Message Tracking

Use message tracking when sending emails to get webhooks when links are clicked, the emails are opened, or when someone replies.

Processing Historical Webhooks

Configure the hooks you want to get for newly connected accounts. The current default will only send webhooks for data received after the account is created.

If you expect to get a lot of webhooks, even with the default settings, we recommend spreading them over several hosts. Using several hosts will lessen the load and let you process webhooks quickly.

Sample Apps

Use our sample apps as a reference to start using webhooks.