Build a Postman Alert for HackerNews
Tags: api, tutorial, beginners, webdev
Published: 2022-03-17 07:02:32

---
title: Build a Postman Alert for HackerNews
published: true
date: 2022-03-14 15:00:00 UTC
tags: api, tutorial, beginners, webdev
canonical_url: https://blog.postman.com/postman-alert-for-hackernews/
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rhg9edgyomc5z6zvgo9a.jpeg
---

It’s every founder’s worst nightmare: your startup is going viral on [HackerNews](https://news.ycombinator.com/news) (HN), and you hear about it first from a customer, or worse yet, an investor. HackerNews is a message board known for its opinionated pundits stirring up discussions on everything related to technology. While it’s important to keep a pulse on the community, you may not have the resources or bandwidth to scour the interwebs for any mention of your company.

Let’s set up and customize your own Postman alert by cobbling together a few API calls and scheduling a cron job to run on Postman servers. In this example, we can watch HackerNews for any mention of our company, and then get notified on Discord.

![A monitor is like a cron job running on Postman servers](https://blog.postman.com/wp-content/uploads/2022/03/HackerNews-1-1000x340.png)
_A monitor is like a cron job running on Postman servers_

## Set up the alert

Fork the collection from this [HackerNews public workspace](https://www.postman.com/devrel/workspace/49ed8ced-a637-4a35-9c7c-8eb441d21c11/overview) by clicking the orange Run in Postman button below. If you also choose to “watch” the collection, you can get notified about updates when new API workflows are added to the collection.

Next, configure two parameters and schedule a monitor in your own workspace.

**1. Set config** : Under the **Body** tab of the [“Set config” request](https://www.postman.com/devrel/workspace/49ed8ced-a637-4a35-9c7c-8eb441d21c11/request/13191452-be7f6cde-fd5a-49de-9a5f-641f72372c2d), update the `keyword` to the name of your own startup. Then update the `destination` to your own discord webhook (or other type of webhook).

![set the `keyword` and `destination` parameters to configure the monitor](https://blog.postman.com/wp-content/uploads/2022/03/HackerNews-2-1000x547.png)
_Set the keyword and destination parameters to configure the monitor_

**2. Schedule a monitor** : Once you have the alert working locally like you want it, [schedule a monitor](https://learning.postman.com/docs/monitoring-your-api/setting-up-monitor/) to run this collection from Postman servers as frequently as every five minutes.

![Schedule a monitor to run as frequently as every five minutes](https://blog.postman.com/wp-content/uploads/2022/03/HackerNews-3-1000x598.png)
_Schedule a monitor to run as frequently as every five minutes_

And that’s it!

In the next section, let’s see what’s happening behind the scenes.

## The API workflow

![The API workflow to send an alert based on content in HackerNews stories](https://blog.postman.com/wp-content/uploads/2022/03/HackerNews-4-1000x306.png)
_The API workflow to send an alert based on content in HackerNews stories_

If you forked [the collection](https://www.postman.com/devrel/workspace/49ed8ced-a637-4a35-9c7c-8eb441d21c11/collection/13191452-c7564f39-0cac-4939-877e-da91239829bb?ctx=documentation), you can review the code under the **Pre-request Script** and **Tests** tabs for each API call. The API workflow utilizes the first four requests in the collection.

- **`POST` Set config** : The first request “Set config” is a dummy request to [httpbin](https://www.postman.com/postman/workspace/20c9374c-0841-4b30-90b7-731b29821d43/overview). It requires setting two parameters that are saved as collection variables to be used in subsequent requests.
- **`GET` Get HN Top stories** : This request queries the HN API to retrieve the top stories.
- **`GET` Get HN item by id** : The third request queries the HN API to check each story retrieved in the previous step, looking for the keyword specified. Postman will continue to cycle on the current query until there are no more stories to check. If the keyword is detected, Postman moves on to the last request.
- **`POST` Send alert** : This request is only triggered when the keyword is detected in the previous step, and issues an alert to Discord about the HN story containing the keyword. This request can also be updated to trigger alerts on other platforms.

![Conditional logic under the Tests tab to send an alert only when keyword is detected](https://blog.postman.com/wp-content/uploads/2022/03/HackerNers5-1000x598.png)
_Conditional logic under the Tests tab to send an alert only when keyword is detected_

If you caught all of that, then you understand these fundamental concepts in Postman:

- **Collection:** A [collection](https://learning.postman.com/docs/sending-requests/intro-to-collections/) is a group of requests. This is helpful for organizing your work and collaborating with teammates. But it’s also the foundational building block for more advanced features in Postman, such as executing a more complex API workflow.
- **Scripting:** You can add JavaScript code to run before and after an API call as [pre-request and test scripts](https://learning.postman.com/docs/writing-scripts/intro-to-scripts/), respectively. This is the basis of test assertions once you receive a response from the server. But also allows you to control your API workflows, and incorporate branching and looping logic, like we did in this example.
- **Monitor:** A [monitor](https://learning.postman.com/docs/running-collections/scheduling-collection-runs/) is like a cron job running on Postman servers. Lots of people use them to monitor the health of their websites and APIs. But you can also use them to run any kind of API workflow on a scheduled cadence. Monitors are closely related to [webhooks](https://learning.postman.com/docs/running-collections/collection-webhooks/), which are actually monitors triggered by an event.

In addition to this HackerNews alert, browse other samples and documentation for the [Official HN API](https://github.com/HackerNews/API) in [this public workspace](https://www.postman.com/devrel/workspace/49ed8ced-a637-4a35-9c7c-8eb441d21c11/overview). You can swap out HackerNews with other social media sites. Or you can swap out Discord for a different platform to receive a notification. And once you learn how to build one alert, you can build an army of them to be your eyes and ears across the Internet.


The post [Build a Postman Alert for HackerNews](https://blog.postman.com/postman-alert-for-hackernews/) appeared first on [Postman Blog](https://blog.postman.com).