Google Sheets

A sheet that fills itself with every new lead. Free, with no add-ons.

A small script on your sheet asks the API for new leads every few minutes and adds a row for each. It never adds the same lead twice.

  1. 1
    Make an API key. Open a new Google Sheet.
  2. 2
    Extensions → Apps Script. Paste the script below and save.
  3. 3
    Project Settings → Script properties: add VISIONSAGE_KEY with your key.
  4. 4
    Triggers (the clock) → Add trigger → syncNewLeads, time-driven, every 10 minutes. Run it once to give permission.
Google Apps Script
// Google Sheet: Extensions → Apps Script → paste this → Save.
// Project Settings → Script properties → add VISIONSAGE_KEY = your API key.
// Triggers (clock icon) → Add trigger → syncNewLeads → Time-driven → Every 10 minutes.
const API = 'https://api.crm.thevisionsage.com/v1/api';

function syncNewLeads() {
  const props = PropertiesService.getScriptProperties();
  const key = props.getProperty('VISIONSAGE_KEY');
  const since = props.getProperty('LAST_SYNC') || new Date(Date.now() - 24 * 3600 * 1000).toISOString();
  const started = new Date().toISOString();
  const sheet = SpreadsheetApp.getActiveSheet();
  if (sheet.getLastRow() === 0) {
    sheet.appendRow(['Added', 'Name', 'Phone', 'Email', 'Stage', 'Source', 'Lead id']);
  }
  // Leads already in the sheet (column G), so none is added twice.
  const seen = new Set(sheet.getRange(1, 7, sheet.getLastRow(), 1).getValues().flat());

  let page = 1;
  while (true) {
    const url = API + '/leads?pageSize=100&sortOrder=asc&createdFrom=' + encodeURIComponent(since) + '&page=' + page;
    const res = UrlFetchApp.fetch(url, { headers: { Authorization: 'Bearer ' + key } });
    const body = JSON.parse(res.getContentText());
    body.data.forEach(function (lead) {
      if (seen.has(lead.id)) return;
      sheet.appendRow([
        lead.createdAt, lead.name, lead.phone, lead.email,
        lead.stage && lead.stage.name, lead.source && lead.source.name, lead.id,
      ]);
    });
    if (page >= body.meta.totalPages) break;
    page += 1;
  }
  props.setProperty('LAST_SYNC', started);
}

Something missing or unclear? Tell us and we will fix this page.