DEV Community

Cover image for πŸš€ Build Dashboard Using Google Sheets API πŸš€
Saurabh Saha
Saurabh Saha

Posted on

πŸš€ Build Dashboard Using Google Sheets API πŸš€

🎯 Introduction

We currently have candidate login and signup data, but we are not fully prepared to build a dedicated dashboard product to support a client. Developing a new dashboard requires coding effort, particularly integrating UI-based libraries that we are not equipped to handle. Additionally, most existing dashboard services come with additional costs, which we want to avoid for now. βŒπŸ’°

As an alternative, using Google Sheets for a semi-manual dashboard is a great idea, especially since Google offers powerful Apps Script automation. This allows us to keep our data up-to-date without maintaining a full-fledged web-based dashboard. βœ…πŸ“Š

🌟 Solution: Using Google Sheets as a Dashboard

Google provides the necessary infrastructure for handling live data updates within Google Sheets using Apps Script. By leveraging this, we can:

  1. πŸ“‘ Fetch candidate data from our API.
  2. πŸ“„ Store and visualize data in Google Sheets.
  3. πŸ”„ Automate updates using triggers to refresh data periodically.

πŸ”Ή Steps to Implement

  1. πŸ†” Get Google File and Sheet ID

Each Google Sheet has a unique file ID that can be accessed from the URL. Individual sheets within the file have unique sheet IDs.

πŸ” How to Get Google File and Sheet ID

From a Google Sheets URL:
https://docs.google.com/spreadsheets/d/FILE_ID/edit#gid=SHEET_ID

πŸ“‚ File ID: Found between /d/ and /edit
πŸ“‘ Sheet ID: Found after gid= in the URL

  1. πŸ–₯️ Write an Apps Script to fetch and store API data in Google Sheets.

Here is a basic script to fetch data from an API and update Google Sheets:

function fetchAPIData() {
  var url = "https://api.example.com/data";
  var response = UrlFetchApp.fetch(url);
  var json = JSON.parse(response.getContentText());

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.clear();

  var headers = json.headers;
  sheet.appendRow(headers);

  json.rows.forEach(function(row) {
    sheet.appendRow(row);
  });
}
Enter fullscreen mode Exit fullscreen mode
  1. ⏰ Set a Trigger to refresh the data at regular intervals.

  2. πŸ” Secure the API using an App Key for controlled access.

⚠️ Issues Encountered

  1. 🚫 ngrok is blocked – We were unable to use ngrok for API tunneling.
  2. ❌ localhost did not work – Direct local API connections failed.
  3. βœ… Hosting with our existing domain worked – Using an AppRunner custom domain (pointed via GoDaddy) successfully allowed API access.

πŸ—οΈ API Structure
A simple API should return structured JSON data.
The API should parse CSV headers and rows dynamically.

Example JSON structure:

{
  "headers": ["Name", "Email", "Signup Date"],
  "rows": [
    ["John Doe", "john@example.com", "2024-02-01"],
    ["Jane Smith", "jane@example.com", "2024-02-02"]
  ]
}
Enter fullscreen mode Exit fullscreen mode

πŸ”„ Architecture Flow

  1. ⏳ Trigger: Google Apps Script trigger initiates the data refresh.
  2. πŸ”— API Call: Apps Script fetches data from our API.
  3. πŸ” Security: API is secured using an App Key.
  4. πŸ“₯ Google Sheets Update: Data is parsed and inserted into Google Sheets.

πŸ—‚οΈ Flow Diagram:

⏳ Trigger (Google Apps Script) β†’ πŸ”— API Request β†’ πŸ” Secure via App Key β†’ πŸ“₯ Insert Data into Google Sheets

πŸ›οΈ Database Architecture Considerations
To optimize performance, we use Materialized Views in our database. This helps:

  1. ⚑ Reduce direct DB load.
  2. πŸš€ Speed up query execution.
  3. πŸ“Š Improve dashboard response times

🎯 Conclusion

Using Google Sheets as a semi-automated dashboard is an effective and low-cost solution for handling candidate data. With minimal coding effort, we can keep data fresh and provide a functional dashboard without investing in a full-fledged UI-based system. This approach ensures scalability while keeping infrastructure costs low. βœ…πŸ“‰πŸ’‘

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.