Apple Product Tracker with Google Scripts

Published in: Apple Mac - Google Apps Script

The new Apple Tracker tool helps you find Apple Stores near your zip code that are more likely to have stock of the new iPhone and iPad units. The tools is written in Google Apps Script and internally fetches the data from Apple’s website and parses the JSON response to check the stock in various Apple Stores.<PART#>&zip=<ZIP>

All products sold in Apple stores have a unique Part # - like ME313LL/A for iPhone 5S 64 GB Gold AT&T or MF118LL/A for iPad Mini Retina 128 GB Gray Sprint Wifi + Cellular - and the Apple tracker sends an HTTP request to the URL to check availability of that product in Apple Stores near a specific zip code.

Here’s the Google Script that check the iPhone and iPad stock at various Apple Stores automatically.

function trackInventory() {

  var report = ""; // Email Report

  // Find Apple Product that are to be tracked
  var items = SpreadsheetApp.getActiveSheet().getRange("B6:D121").getValues();

  // Check inventory of Apple Stores near this zip code
  var zip = UserProperties.getProperty("zip");

  for (var i=0; i<items.length; i++) {

    if (items[i][2] === "Y") {

      // Check product availability at the given zip code
      var url = ""
                              + encodeURIComponent(items[i][1]) + "&zip=" + zip;

      var locations = "";

      try {

        var response = UrlFetchApp.fetch(url);
        var json = Utilities.jsonParse(response.getContentText());

        for (var j=0; j<json.body.stores.length; j++) {
          // Is the product (Apple Part) listed as "available" in that Apple Store
          var store = json.body.stores[j];
          if (store["partsAvailability"][items[i][1]]["pickupSearchQuote"] != "Unavailable for Pickup") {
            locations += "<li><small><a href='" + store["directionsUrl"] + "'>" + store["storeDisplayName"] + "</a> "
            + store["address"]["address2"] + ", " + store["city"] + " " + store["address"]["postalCode"]
            + " " + store["state"] + " (" + store["phoneNumber"] + ")</small></li>";

        if (locations.length) {
          report += "<p><strong><a href='" + storeURL(items[i][0])
                 + "'>" + items[i][0] + "</a></strong> is currently available at: </p><ul>";
          report += locations + "</ul>";

      } catch (e) {


  // Send HTML Mail with the product availability details
  if (report.length) {
      MailApp.sendEmail(UserProperties.getProperty("email"), "Apple Tracker", report, {htmlBody: report});

function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menu = [
    {name: "Step 1: Initialize", functionName: "OpenWizard"},
    {name: "Step 2: Start Tracking", functionName: "OpenWizard"}

  ss.addMenu("Apple Store Tracker", menu);
  ss.toast("Please click the Apple Tracker menu above to continue..", "", 5);

// Create UI to get email address and zip code from the user
function OpenWizard() {

  var app = UiApp.createApplication().setTitle('Apple Inventory Tracker').setHeight(160).setWidth(300);
  var top_panel = app.createFlowPanel();

  top_panel.add(app.createLabel("Please enter your ZIP code"));
  var zip = app.createTextBox().setName("zip").setWidth(250).setValue(UserProperties.getProperty("zip"));

  top_panel.add(app.createLabel("Please enter your Email Address"));
  var email = app.createTextBox().setName("email").setWidth(250).setValue(UserProperties.getProperty("email"));

  var btn = app.createButton("Start Tracking");

  var handler = app.createServerHandler('storeDB').addCallbackElement(zip).addCallbackElement(email);


// Get the Apple Store URL based on the Part Name
function storeURL(partName) {

  var storeURL;

  if ("iPad Air") != -1)
    storeURL = "";
  else if ("iPad Mini Retina") != -1)
    storeURL = "";
    storeURL = "";

  return storeURL;

// Store the Zip and Email address in User Properties
function storeDB(e) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();


  var app = UiApp.getActiveApplication();
  return app;

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Apple Mac - Google Apps Script

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube