# Managing calendar event changes with Push Notifications

How do you get alerts when there is a change to your calendar event? Cronofy's push notifications allow you to proactively inform clients of real-time changes. Read to technical guide.


Keeping apps synced with calendar events is crucial. Instead of inefficient polling, push notifications provide real-time updates to users. This article explores how Cronofy’s API enables instant event change alerts, ensuring efficient resource use and timely updates.

Web push notifications are messages sent from an application to a user's device, even when the user is not actively browsing the site. They enable real-time communication with users, allowing websites to deliver timely updates, alerts, and personalized content. Push notifications are an effective alternative to polling, enabling the server to proactively send data to the client when new information is available, reducing unnecessary network traffic and server load.

To understand this more, lets see how [Cronofy](https://www.cronofy.com/developer), a scheduling infrastructure layer with [calendar APIs](https://www.cronofy.com/developer/calendar-api), uses push notifications to inform you once a change has occurred so that you can then call the API and retrieve the changes.

The result of this is being able to keep your view of the data up-to-date while only performing updates when there has been genuine changes to it.

## Keeping your application up to date with an end user’s calendar using Push Notifications

First, if you haven’t already, [create a developer account](https://app.cronofy.com/sign_up/developer) with Cronofy (it’s free for devs 💫). You can find the [getting started guide](https://docs.cronofy.com/developers/getting-started/) for building scheduling functionality into your application which will be good context to follow along for the rest of the guide.

In order to be certain that the user’s events stay up to date in your system, you can utilise [Push Notifications](https://docs.cronofy.com/developers/api/push-notifications/), [Read Events](https://docs.cronofy.com/developers/api/events/read-events/), and regular weekly syncs.

**Step 1.** Make the [Create Push Notifications Channel](https://docs.cronofy.com/developers/api/push-notifications/create-channel/) request in Postman.

[Example request](https://docs.cronofy.com/developers/api/push-notifications/create-channel/#example-request)

```http
POST /v1/channels HTTP/1.1
Host: {data_center_url}
Authorization: Bearer {ACCESS_TOKEN}
Content-Type: application/json; charset=utf-8

{
  "callback_url": {CALLBACK_URL},
  "filters": {
    "calendar_ids": ["cal_n23kjnwrw2_sakdnawerd3"],
    "only_managed":false
  }
}
```

**Step 2.** Create, move, or delete an event in Google Calendar to trigger a change notification.

**Step 3.** See the ‘change’ push notification come through.

[Example Push Notification Request](https://docs.cronofy.com/developers/api/push-notifications/#example-push-notification-request)

```http
POST {CALLBACK_URL_PATH} HTTP/1.1
Host: {CALLBACK_URL_HOST}
Content-Type: application/json; charset=utf-8
Cronofy-HMAC-SHA256: {Base64(HmacSHA256(body_bytes, CLIENT_SECRET))}

{
  "notification": {
    "type": "change",
    "changes_since": "2024-10-23T09:24:16Z"
  },
  "channel": {
    "channel_id": "chn_54cf7c7cb4ad4c1027000001",
    "callback_url": {CALLBACK_URL},
    "filters": {
      "calendar_ids": ["cal_n23kjnwrw2_sakdnawerd3"],
      "only_managed":false
    }
  }
```

Note that ‘change’ notifications will include a `changes_since` parameter that can be used as the `last_modified` parameter for a subsequent [Read Events](https://docs.cronofy.com/developers/api/events/read-events/) request, allowing integrators to only have to query for data that changed since the last observed change within Cronofy.

**Step 4.** Run a [Read Events](https://docs.cronofy.com/developers/api/events/read-events/) call on the associated `calendar_id` to poll for the changes made that triggered the notification.

[Example Request](https://docs.cronofy.com/developers/api/events/read-events/#example-request)

```http
GET /v1/events?from={FROM_DATE}&to={TO_DATE}&tzid={TZID} HTTP/1.1
Host: {data_center_url}
Authorization: Bearer {ACCESS_TOKEN}
```

An important caveat in this context is the fact that every API will have different sync windows which will determine the balance between the frequency of your application performing sync operations (potentially impacting performance) and how current the data remains (impacting accuracy and responsiveness). In Cronofy’s case, sync windows start at 42 days in the past and ends 201 days into the future.

To avoid overloading the notification channel, a Push Notification will not be triggered when an event becomes visible due to the sync window moving. As a result, the event will not get synced unless you schedule regular polling of the calendar to catch any events moving into the sync window. To sync these events, you can set up a manual Read Events call towards the end of the sync window and catch the events far in advance. For example, a weekly request polling for events before the end of our default sync window can look like this:

```http
GET /v1/events?from={194_days_from_today}&to={201_days_from_today}&tzid={TZID} HTTP/1.1
Host: {data_center_url}
Authorization: Bearer {ACCESS_TOKEN}
```

When leveraging push notifications in your application, consider the frequency of running syncs to ensure full coverage of event changes are captured. In the case of building calendar push notifications, we recommend running a weekly or daily sync by carrying out a read events call for all events for the calendar. While the other steps will ensure complete coverage, this occasional full sync provides robustness.

You’ve now learnt how to utilize push notifications in the context of calendar event changes but the principals covered here can also be applied to other contexts such as profile disconnections, initial sync completion after an end-user connects their calendar to your platform for the first time, or when they submit a GDPR deletion request.

Create your developer account and start scheduling

Start Integrating

[Technical Consultation](/book-a-demo-api)

### Cronofy Partners with Whereby for Integrated Video Calls and Streamlined Scheduling

Cronofy has partnered with Whereby to further accelerate scheduling and video conferencing capabilities for product builders. Our shared vision of creating secure, scalable and flexible solutions for developers and product teams, is now set in motion.

Blog Post

2024-09-24T10:31:00.000Z

---

### An API that scales with you: How Heal.me solved telehealth calendar sync headaches

Learn how Heal.me delivered reliable calendar synchronization to patients and practitioners on a wider scale. We speak to CTO Chad Agate to understand how Cronofy provided a reliable, long-term solution for their needs.

Case Study