I didn’t manage to get an iPhone on launch day. I was banking on using the “reservation” system to get it the next week, but Apple Store’s website doesn’t update squarely at 10pm anymore with what’s in stock, rather, around the clock.

While using the availability checker on Apple’s website, I noticed that is used a simple JSON request:

The response is a fairly clear:


I thought, what if I write a script that repeatedly checks this JSON, and notifies me when the item I want is in stock? It turns out, it’s very easy. Check it out:


To begin with, create an empty folder, initialize git, and put two empty files in it: Gemfile and alerter.rb.

> mkdir alerter
> cd alerter
> git init
> touch Gemfile
> touch alerter.rb

Here’s how the Gemfile is set up:

source 'https://rubygems.org'
gem 'httparty' # to make http requests
gem 'twilio-ruby' # for twilio

Go back to the console and run bundle install to get these gems.

Now go to http://twilio.com to get a Twilio account if you don’t have any. (You need to upgrade it so it can place phone calls.)


Get alerter.rb from Github (it didn’t format too well here).

You should replace account_sid, auth_token, and the to/from parameters of @call with your own Twilio account info (from will be your special Twilio number, to will be your regular number). Put your zip code in zip.

To find out the correct model number for the phone you want, go to Apple Store and select the color/capacity/carrier configuration you want, then click “Continue”. The next page will have the model number in the URL.

https://buyiphone2.apple.com/WebObjects/IPACustomer.woa/wa/IPAPreAuthAction/homePage?carrier=verizon_US&product=ME347LL/A&sf=us

Here I have ME347LL/A which is the Gray 64G iPhone 5s for T-mobile.


Now that you have all files set up, let’s see if it works. In the console, run your app.

> ruby alerter.rb

This will show you the results.

not found in grandcentral@apple.com
not found in west14thstreet@apple.com
not found in soho@apple.com
not found in fifthavenue@apple.com
not found in upperwestside@apple.com

To check if the phone call works, try entering a model number that has wide availability, such as an iPhone 4: MF263LL/A. It should list it as available, and give you a call.


Let’s now set up Heroku. (I’m assuming your Heroku credentials are already set up. If not, follow these instructions). In the console, type

> heroku apps:create  
Created http://mystic-wind-83.herokuapp.com/ | git@heroku.com:mystic-wind-83.git

This will create a new app, with a random name. Now we can push the code to it.

> git add .
> git commit -am "initial commit"
> git push heroku master
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 912 bytes, done.
Total 6 (delta 1), reused 0 (delta 0)

Let’s now add the scheduled job:

heroku addons:add scheduler:standard

To configure the scheduler, open your app in Heroku’s website and click Heroku Scheduler.

Then click Add job and configure it like the following:

That’s it! You should get a phone call with good news :)