I created a simple app to notify me when someone canceled their reservation to the Mather Campground in the Grand Canyon National Park area. I did this only in 2 hours by utilizing Azure Functions and Twilio integration - for free.
My colleague and I decided to have an extended weekend in the Grand Canyon. We both like hiking, nature, and camping life. I was responsible for finding a campsite for us. We decided to stay in Mather Campground on the South Rim, which is open all year. Unfortunately, we soon found out that all campsites in Mather Campground were already reserved for our desired trip dates on 16 April – 18 April. Their website was showing “Unavailable” for our desired trip dates.
Our trip was still a couple of weeks away, and I wondered if there will be any cancellations. Their reservation system does not have a waiting list where you could sign up. I didn’t want to spend my days refreshing the browser in their reservation system. Mather Campground is a large facility with over 300 campsites. I was pretty sure there must be cancellations, and probably they’ll also release canceled sites back to the online reservation system.
🕵️ Taking a look at API
I took a closer look at the Mather Campground reservation system at www.recreation.gov. Using Chrome Web Developer Tools, I found out they have quite a simple API for requesting campsite availability for one month at a time. The response to the API request was easy to read. The response contained availability per date for all the campsites.
I realized I could have a simple app to poll API for cancellations and notify when the site comes available. This way, I could immediately get a notification when someone cancels their campsite.
To develop a solution quickly, I choose to create Azure Function for polling the API endpoint and Twilio to notify me via SMS there is a site available.
💡 Creating a scheduled serverless function
The first step is to register yourself to Azure Portal. You can get a $200 credit if you don’t yet have an Azure account. That’s more than enough for this simple job.
After you have an account, go and create a Function App, which is a container for serverless Azure Functions. You need to choose a runtime stack to run your functions. In my case, I decided to write my app with JavaScript development, so I choose Node.js.
The next step is to create an actual Azure Function. There are multiple function templates available, but the best for this purpose is the Timer trigger -template.
After Azure Function is created, you can start coding in Azure Portal. I decided not to integrate my project to Visual Studio Code, but to do all development in the portal. You won’t bet best developer experience there, but my app was simple enough to just use a web browser for developing the app.
The function is quite simple. It creates an API request, converts the response to JSON, loops all the sites in response, and checks if it is available on desired trip dates. If a site is available, it will send SMS using Twilio integration.
🖥️ Azure Function with Twilio SMS integration
I created a free Twilio account for my app to send me SMS when one of the sites becomes available. With a free account, you automatically get $25 free credit that’s more than enough for this purpose.
Probably the most challenging part is to set up Twilio integration if you are not familiar with the Azure Function app. First, you need to add integration to the Azure Function in the “Integrations”-tab. What’s a bit confusing, for Twilio Account SID setting and Auth Token setting properties, you don’t insert actual values there, but the configuration key in app settings.
After you have configured Twilio for your function, you need to add TwilioAccountSid and TwilioAuthToken to app configuration in Azure Function App.
After all this, you should now be ready to enable your function.
Digging around and developing took about 2 hours. If you are already familiar with Azure App Service & Azure Functions, you can probably do it much quicker.
💬 SMS arrived sooner than expected
The following day, I received multiple SMS messages from my function saying a site is available. I immediately navigated to the reservation system, saw a free site, and reserved it for us.
We had a fantastic time in the Mather Campground and Grand Canyon. We spent two days hiking in Bright Angel and South Kaibab trails. The views on the trails there are unbelievable, and the canyon area is massive, something you can’t easily capture in one picture. In the evenings, we had a campfire, cooked some food, and enjoyed a peaceful environment. We also see multiple tame deers near our tent trying to find food. I can recommend Grand Canyon to anyone interested in hiking and exploring the awesome nature destination.
You can download the code for the serverless function here. Enjoy!