# Google Sheets Integration Guide

> Build live UAE real estate trackers in Google Sheets. Use Apps Script to pull Property Finder APIs and Datasets data directly into your spreadsheets for automated market research.

Source: https://uaepropertyapi.com/guides/google-sheets

## Introduction

Google Sheets is a powerful, low-cost alternative to expensive real estate analytical software. By combining Google Apps Script with Property Finder APIs and Datasets, you can build self-updating property trackers, yield calculators, and market comparison dashboards—all without hosting a single server.

This guide provides a professional "copy-paste" template for pulling high-fidelity UAE listing data into your spreadsheets.

## Prerequisites

- **Google Account**: Access to Google Sheets.
- **RapidAPI Credentials**: An active subscription to the [Propertyfinder-UAE-Data API](https://rapidapi.com/happyendpoint/api/uae-real-estate-property).
- **Basic Spreadsheet Knowledge**: No advanced coding required.

## Setup: Initializing the Connection

1.  Open a new **Google Sheet**.
2.  Navigate to **Extensions > Apps Script**.
3.  Delete the default `myFunction` and paste the configuration below.

```javascript
/* Global Configuration */
const MARKET_API = {
  KEY: "YOUR_RAPIDAPI_KEY",
  HOST: "uae-real-estate-property.p.rapidapi.com",
  BASE_URL: "https://uae-real-estate-property.p.rapidapi.com"
};
```

## Implementation: Automated Listing Ingestion

This script creates a professional table of live properties. It handles API authentication, JSON parsing, and automatic formatting in a single execution.

```javascript
function syncMarketData() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  let sheet = ss.getSheetByName("Live Inventory");
  
  if (!sheet) {
    sheet = ss.insertSheet("Live Inventory");
  }

  // Define Market Query (e.g., Apartments for Sale in Downtown Dubai)
  const endpoint = `${MARKET_API.BASE_URL}/search-buy?location_id=41&property_type=apartment&page=1`;
  
  const options = {
    method: "GET",
    headers: {
      "x-rapidapi-key": MARKET_API.KEY,
      "x-rapidapi-host": MARKET_API.HOST
    },
    muteHttpExceptions: true
  };

  const response = UrlFetchApp.fetch(endpoint, options);
  const result = JSON.parse(response.getContentText());
  const listings = result.data;

  // Prepare Spreadsheet Headers
  sheet.clear();
  const headers = [["Property Title", "Price (AED)", "SQFT", "Price/SQFT", "Beds", "Baths", "Property ID"]];
  sheet.getRange(1, 1, 1, headers[0].length).setValues(headers).setFontWeight("bold").setBackground("#f3f3f3");

  // Map JSON to Rows
  const rows = listings.map(p => [
    p.title,
    p.price.value,
    p.size.value, // size.unit is "sqft"
    p.size.value > 0 ? (p.price.value / p.size.value).toFixed(2) : 0,
    p.bedrooms,
    p.bathrooms,
    p.property_id
  ]);

  if (rows.length > 0) {
    sheet.getRange(2, 1, rows.length, headers[0].length).setValues(rows);
    sheet.getRange(2, 2, rows.length, 1).setNumberFormat("#,##0"); // Format Price
  }

  SpreadsheetApp.getUi().alert(`Sync Complete: ${rows.length} listings ingested.`);
}
```

## Advanced: Custom Formulas for Location IDs

Tired of looking up Location IDs? Build a custom function to find them directly within your Sheet cells.

```javascript
/**
 * Resolves area names to Propertyfinder Location IDs.
 * Usage: =MARKET_LOCATION("Dubai Marina")
 */
function MARKET_LOCATION(query) {
  if (!query) return "Enter Query";
  
  const url = `${MARKET_API.BASE_URL}/autocomplete-location?query=${encodeURIComponent(query)}`;
  const options = {
    headers: {
      "x-rapidapi-key": MARKET_API.KEY,
      "x-rapidapi-host": MARKET_API.HOST
    }
  };
  
  const res = JSON.parse(UrlFetchApp.fetch(url, options).getContentText());
  const firstMatch = res.data[0];
  
  return firstMatch ? firstMatch.id : "No Match Found"; // e.g. 50 for Dubai Marina
}
```

## Operational Continuity: Setting Triggers

Keep your data fresh without clicking a button:

1.  In the Apps Script editor, click the **Triggers (Clock Icon)** on the left.
2.  Click **+ Add Trigger**.
3.  Select `syncMarketData` as the function to run.
4.  Set Event Source to **Time-driven**.
5.  Set Interval to **Day timer** or **Hour timer** based on your research needs.

## Investment Benefits

- **Low-Cost Analytics**: Build institutional-grade portfolio trackers for the price of an API subscription.
- **Collaborative Sharing**: Share your live market dashboards with clients or team members via Google Sheets' native sharing.
- **Automated Yield Monitoring**: Link multiple sheets to calculate Gross Rental Yields (GRY) automatically as prices update.
- **Data Persistence**: Archive historical price data daily to build your own community-level price index.
- **Zero Maintenance**: Apps Script runs on Google's infrastructure—no servers to patch or update.

## Next Implementation Steps

1.  **Modeling**: Use the [Investment Analysis Use Case](/use-cases/investment-analysis) to build your yield formulas.
2.  **Scale**: If your data exceeds 10,000 rows, consider moving to the [Python Guide](/guides/python) with Pandas integration.
3.  **No-Code**: Explore the [Zapier/Make Guide](/guides/no-code) to send Slack alerts when prices drop.
