---
updatedAt: 2025-06-04T20:41:24.000Z
agentTools:
  projectIndex: https://docs.tomorrow.io/llms.txt
---

# Set Up Severe Weather Alerts Around a Geofence

```node Node
const fetch = require("node-fetch");

// set the Alerts POST endpoint as the target URL
const postAlertsURL = "https://api.tomorrow.io/v4/alerts";

// get your key from app.tomorrow.io/development/keys
const apikey = "add your API key here";

// choose an insight category, such as fires, winter or temperature
const insight = "winter";

// specify the name and notification details, later detailed in the webhook payload
let name = "Winter Weather Hazards";

const notifications = [
  {
    type: "PUBLISH",
    title: "Winter Weather Report",
    description:
      "Our sources issued a new hazardeous winter weather announcement. Stay safe.",
  },
];

// create a severe weather alert with all the body parameters as options
const postAlertsParameters = {
  name,
  insight,
  // isActive: true, (default to true)
  notifications,
};

fetch(postAlertsURL + "?apikey=" + apikey, {
  method: "POST",
  compress: true,
  body: JSON.stringify(postAlertsParameters),
  headers: { 'Content-Type': 'application/json' },
})
  .then((res) => res.json())
  .then((json) => {
    // set the Alerts Locations Link POST endpoint as the target URL
    const postAlertsLocationsLinksURL =
      "https://api.tomorrow.io/v4/alerts/" + json.data.alert.id + "/locations/link";
  
  	// name a pre-defined location by its ID
  	const locationId = "59f35a7f65d7a20007abb096";

  	// link the location to the alert, so it will start monitoring for the weather events
    fetch(postAlertsLocationsLinksURL + "?apikey=" + apikey, {
      method: "POST",
      body: JSON.stringify({
        locations: [locationId],
      }),
      headers: { 'Content-Type': 'application/json' },
    })
      .then((res) => res.json())
      .catch((err) => console.error("error: " + err));
  })
  .catch((err) => console.error("error: " + err));
```

```json Response Example
// POST /alerts
{
    "data": {
        "alert": {
            "id": "3805b6c8-dd6f-4dac-9dc2-fb9ea2702a73",
            "insight": "winter",
            "name": "Winter Weather Hazards",
            "isActive": true,
            "notifications":  [
              {
                type: "PUBLISHED",
                title: "Winter Weather Report",
                description:
                  "Our sourced issued a new hazardeous winter weather announcement. Stay safe.",
              },
            ],
            "createdAt": "2021-03-25T06:49:34+0000"
        },
    }
}

// POST /alerts/{alertId}/locations/link
{
    "data": {
        "location": {
            "id": "5e82fb82b66492001218aaf3",
            "name": "Tomorrow.io Headquarters",
            "geometry": {
              "type":"Polygon",
              "coordinates":[...coordinates]
            },
            "createdAt": "2021-03-25T06:50:21+0000"
        }
    }
}





```

# Introduction to this guide

<!-- node@3-4 -->

**Our [advanced alerting system](https://docs.tomorrowio/reference/overview-alerts) allows you to subscribe locations of interest to national weather advisories with just a few steps.**

In this guide, we'll walk you through setting up an alert for Winter Weather Hazards, notifying our staff in Boston in our slack channel.

# Get your key

<!-- node@6-7 -->

Before we begin, make sure to [signup to our platform](https://www.tomorrow.io/weather-api/) and, once logged in, [grab your key](https://app.tomorrow.io/development/keys).

# Choose an insight category

<!-- node@9-10 -->

First, we need to [choose an insight category](https://docs.tomorrow.io/reference/insights-categories-overview) that covers the weather events that we'd like to monitor with alerts.  

In our case, we're going to automatically notify the company employees to stay home and safe whenever there's an event of `winter` type.

Note that currently our collection mainly covers US weather reports issued by NWS. This will be extended soon, so keep an eye out for updates.

# Specify the name and notification details

<!-- node@12-22 -->

Next, we're going to add some descriptive text for these specific alerts that we can pull directly from the webhook's payload to enrich our message - without needing additional handling by the distribution service.

Alerts that are based on a **custom insight** can be sent `PRIOR`/`START`/`END` of the detected weather event, because they are calculated throughout the day. However, **category insight** alerts rely on external sources and only trigger notifications as they are `PUBLISHED`.

# Create a severe weather alert

<!-- node@24-38 -->

Now that we have all of the parameters, we can create the alert in the system, to be later on linked to our locations of interest.

By default, all alerts are created as active. If you wish the activate them at a later stage, make sure to set `isActive` as false and thereafter use the [/activate](https://docs.tomorrow.io/reference/put-alerts-id#post-alerts-id-activate) and [/deactivate](https://docs.tomorrow.io/reference/put-alerts-id#post-alerts-id-deactivate) endpoints.

# Link a predefined location to alert

<!-- node@39-57 -->

Unlike custom insight alerts, these can be linked to any [location type](https://docs.tomorrow.io/reference/locations-overview) - be it `Point`, `Polygon`, or `Polyline` - as long as it's is predefined in the system.

This uses the `locationId` of our headquarters neighborhood in Boston - Downtown. When we set it up, we used a Polygon geometry, to create a "geofence" around the office to make sure no nearby weather events are missed.

# Configure the webhook URL



Finally, you need to [connect the platform to your webhook URL](https://app.tomorrow.io/development/webhooks), listen to incoming events, and parse the [notification payload](https://docs.tomorrow.io/reference/overview-alerts) to distribute it to your chosen channel.

There are a few ways to go about this. Some are easier than others. Read our guide on [Alert Listeners](https://docs.tomorrow.io/reference/alert-listeners) to learn how to set that up. 

We recommend getting started with our one-click Zapier integration that allows you to send notifications via SMS, email, and slack without additional coding.