Making sure your website or API is up and running well can be a round-the-clock job. To help in this tireless effort, we can make uptime reports and status alerts visible within the we frequently use, like . With a platform like , an integration like that is nearly effortless. This guide will show you how to set up an API on that will ping a URL and send a message to if the URL doesn’t return a 2xx status code. It will leverage which allow you to execute APIs based on nearly any schedule. tools Slack Standard Library Standard Library Slack Standard Library’s scheduled tasks, If you’re not familiar with , we’re a serverless platform that enables everyone to build, ship, and integrate scalable APIs in a matter of seconds. With the help of our online text editor, , you can do it right from your browser. Standard Library Code.xyz Step 1: Create a Slack App Head over to the , and click “ ” in the top-right corner of the screen. After a moment, you’ll be redirected to a page labeled “ ”. On the left side of the screen, you’ll see “ ” under the “ ” category. Slack app dashboard Create New App Basic Information OAuth and Permissions Features Once there, scroll down to “ ”. We need the bot to be able to send messages to Slack on behalf of itself. That means we need to give it “ ” permissions, so search for that in the “ ” drop-down. Scopes chat:write:bot Select Permission Scopes With the desired permissions set, scroll back up to the top of the “ ” page and click the green “ ” button. Once you authorize it, the page will refresh and where the install button once was will be an OAuth token. Click copy; you’ll need that in just a moment. OAuth and Permissions Install App to Workspace Step 2: Get the Ping API Template With Slack all squared away, open up . If you follow that link, a template for the ping API will automatically open. Otherwise, you can click on the “ ” tab and search for “ ”. Code.xyz Community API Sources steve/ping Once it’s loaded, you’ll land on the endpoint. It takes a single parameter, . The function makes an HTTP request to and checks if the status code is in the 2xx range. If it’s not, it uses the to send a message to a channel specified by the environment variable . __main__.js url url Slack SDK SLACK_CHANNEL_ID The heavy lifting is done in the file. Feel free to peruse that file, but in essence, it makes a GET request to a URL and records some information about the request. It will return the status code and timing information like the time to first byte and total request duration. /src/request.js After the ping, we check if the status code is less than 200 or greater than 299. If it is, message slack with the details of the request, formatted with the function . takes the object returned by the function, stringifies it, and wraps it up in triple backticks. Slack will display anything surrounded by three backticks as a code block, which can make JSON look a little cleaner. For more on formatting see the . formatPing formatPing request Slack documentation Step 2b : Set the Environment Variables If you open up , you’ll see two environment variables, and . The former is what we just got from the Slack app dashboard, and the latter is the name of the channel you want the bot to post to, like or . Make sure you fill out the “ ” set, as shown below. env.json SLACK_OAUTH_TOKEN SLACK_CHANNEL_ID #general #alerts dev Now seems like an appropriate time to test this API out. Go back to and press to open the parameters pane in the bottom-left of the screen. Type in a URL and hit enter. If all is well for whatever website/API is at that URL, you should see nothing! __main__.js cmd/ctrl+b That’s because if the ping API can reach the URL with a 2xx status code, it’s a noop. To try a failing case use as the URL. In the Code.xyz results panel you’ll see the response from Slack’s API saying a message was sent. If you navigate to the channel you put in — [https://bad.stdlib.com/](http://bad.stdlib.com/) env.json You’ll see a message that was unreachable, and some information about the request. https://bad.stdlib.com/ Step 3: Set a Scheduled Task With the ping API up, we can now schedule the API to run every few minutes. Click on the “ icon at the top of . On the right side of the scheduled tasks page, under “ ”, search for the API you just deployed. tasks” Code.xyz Scheduled a New Task Once you open it, you’ll see the task creation widget. To set the schedule, you have two options. By default you pick from a few drop-downs, allowing you to create intervals like “run once a minute” or “run twelve times an hour”. You can also click on “ ” if you like cron syntax. Whichever way you choose, it’s probably best to have the API run at least once every five minutes. Advanced (cron) Click the blue “ and the task should appear on the left side of the screen. Schedule Task” Digging Deeper There are many ways to expand upon this simple ping API. For instance, maybe you want to include status codes in the 3xx range (redirects) as acceptable. Well, all you have to do is change one line of code! Changing if (ping.statusCode < 200 || ping.statusCode > 299) {...} to if (ping.statusCode < 200 || ping.statusCode > 399) {...} Will do the trick! Now perhaps you guilty of not checking Slack as often as you should, and prefer good old SMS. With , SMS integration is just a line of code away! In fact; there is another endpoint in the ping API already set up with SMS notifications. Open up , and you’ll see — Standard Library extra.js It’s the same as but with the extra conditional to check if a phone number was provided. If so, it’ll send a message to prompting the recipient to get on Slack to see whats happening. __main__.js The point of these small changes is to show that at the end of the day scheduled tasks, and any API on Standard Library for that matter, are just JavaScript and fully customization to your exact use case. That’s All! I hope this tutorial has been helpful in showing you how easy it is to get started with . For more inspiration as to how you can better use , you can check out more guides written by the team . If you have a neat idea you’d like to share, reach out to me directly by e-mail: , or follow the team and on Twitter. Standard Library Standard Library here steve@stdlib.com Standard Library me Steve Meyer is a recent graduate of Oberlin College and Software Engineer at Standard Library. When he’s not programming, you can find him baking bread, or playing Spider-Man.