knowhash Get knowhash
← All connection guides
How-to · Connect Deck

Connect knowhash Deck to Notion, free, with a Google Sheets script

Your Deck contacts arrive in a Notion database by themselves, with their LinkedIn link, headline, company, location, notes and photo, plus a link back to their Deck card. When you change someone in Deck, their Notion page is updated, not duplicated. Each Deck card gets an Open in Notion button that goes straight to their page, on your phone too.

  • The script builds the database for you. No fields to set up by hand.
  • Nothing in between. A short script inside your own Google Sheet talks straight to Notion. No Zapier, no Activepieces, no third party holding your contacts.
  • Their photo becomes their page icon, the same photo Deck shows.
  • Every 15 minutes, only people whose details changed are sent.

You'll need knowhash 0.9.5 or later with Deck set up and a few contacts in it. New to Deck? Open any LinkedIn profile, click Deck in the knowhash panel, then Set up Deck.

Step 1: Make a page in Notion for your contacts

  1. New to Notion? Go to notion.com, click Get Notion free and continue with Google. Choose For work, then the Free plan, and skip inviting teammates and the desktop app.
  2. Quickest: open the knowhash Contacts template, click Duplicate (top right) and choose Add to Private. You get a knowhash page with the database already in it, and the script fills that database instead of making a new one.
  3. Or make your own: in the left sidebar, hover over Private, click the + that appears, and call the page knowhash. The script adds the database for you.
  4. Open the page and copy its link: ••• at the top right, then Copy link. You'll paste it in step 4.

Notion's Free plan holds up to 1,000 blocks, and each contact is one block, so roughly 1,000 contacts. The welcome pages Notion adds count too; delete them if you want every bit of room. (Notion pricing)

Step 2: Create a Notion token

The token lets the script add pages to your Notion as you. It reaches only what you can see, and you can revoke it at any time.

  1. Go to notion.so/developers/tokens and click New token.
  2. Name it knowhash Deck and set Expiration to 1 year.
  3. Under Capabilities, keep Notion API ticked. Untick Workers: the script doesn't need it.
  4. Click Create token and copy it. Notion shows it only once.
Notion's New personal access token form: name knowhash Deck, expiration 1 year, Notion API capability ticked

No New token button? On Notion's Free plan only the workspace owner can create tokens. If someone else owns your workspace, ask them, or make your own free workspace for your contacts.

Step 3: Add the script to your sheet

  1. Open your knowhash sheet (in Deck, open in Google Sheets at the bottom of the list), then Extensions → Apps Script.
  2. Already using the Google Contacts script? Keep it. Click + next to Files, choose Script, and name the new file notion. Otherwise, use the empty Code.gs.
  3. Click Copy the script below, paste it into the file (replacing anything there), and click the save icon.
Choose your fields optional: which fields go to Notion, and what they're called

Untick anything you don't want in Notion, and rename fields to suit your workspace. The script below changes as you go, so copy it when you're happy. Name is always included because Notion needs a title, but you can rename it. Changing a name later adds a new field in Notion; the old one keeps its data.

Includeknowhash columnName in Notion
/**
 * knowhash Deck -> Notion
 * Version 2026-12-03: if your page already has a "knowhash Contacts" database (for example from the
 * knowhash Notion template), setup uses it instead of creating a second one, adding any missing fields.
 * Since 2026-11-30: choose which fields go to Notion, and what they're called (NT_FIELDS below),
 * and an Open in Notion button is added to your Deck cards for you.
 *
 * Copies the people in your knowhash Deck into a Notion database (it finds or creates it), and keeps
 * them up to date. Runs inside your own Google Sheet: your contacts go straight from Google to
 * Notion, never through knowhash or any other service.
 *
 * Setup (once): make a Notion page and a personal access token, add this as a new script file,
 * choose "setupNotion" and click Run. Switch to your sheet: it asks for your token, then for the page's link.
 * After that it runs by itself every 15 minutes and only sends people whose details changed.
 *
 * It adds three columns at the far right of your Contacts tab:
 *   nt_id      the Notion page ID (or "deleted" if you deleted the person in Notion)
 *   nt_link    a direct link to the person in Notion, for an "Open in Notion" Deck button: {nt_link}
 *   nt_synced  the kh_updated_at value last sent, so unchanged people are skipped
 *
 * To choose which fields go to Notion and what they're called, change NT_FIELDS (or use the guide page).
 *
 * Every name here starts with Notion or NT_, so it sits happily beside the Google Contacts script.
 *
 * Your token is kept in this script's own settings (Project Settings > Script Properties),
 * not in the code or the sheet. To change it, run "changeNotionToken".
 *
 * Guide: https://knowhash.com/how-to/deck-notion/
 */

/** @OnlyCurrentDoc */
// The line above asks Google for access to this one spreadsheet only, not all your sheets.

const NT_SCRIPT_VERSION = '2026-12-03'; // compare with the guide page to see if a newer copy is there

const NT_TAB = 'Contacts';      // the tab knowhash writes your Deck to
const NT_DB_TITLE = 'knowhash Contacts';
const NT_EVERY_MINUTES = 15;    // how often to check for changes (1, 5, 10, 15 or 30)

// FIELDS:START
// Your fields: [knowhash column, name in Notion, include it]. Set these on the guide page, or edit them here.
// Name is always included: it's Notion's title field. Changing a name later adds a new field in Notion;
// the old one stays, with its data, for you to delete or keep.
const NT_FIELDS = [
  ['kh_name',        'Name',            true],
  ['kh_first_name',  'First name',      true],
  ['kh_last_name',   'Last name',       true],
  ['kh_email',       'Email',           true],
  ['kh_other_email', 'Other email',     true],
  ['kh_phone',       'Phone',           true],
  ['kh_company',     'Company',         true],
  ['kh_headline',    'Headline',        true],
  ['kh_location',    'Location',        true],
  ['kh_profile_url', 'LinkedIn',        true],
  ['kh_connection',  'LinkedIn status', true],
  ['kh_notes',       'Notes',           true],
  ['kh_deck_url',    'knowhash Deck',   true],
];
// FIELDS:END

const NT_ID = 'nt_id', NT_LINK = 'nt_link', NT_DONE = 'nt_synced';
const NT_API = 'https://api.notion.com/v1/';
const NT_VERSION = '2026-03-11';
const NT_PROPS = PropertiesService.getScriptProperties();

/** Run this once. It asks for your token and page, finds or creates the database, starts the timer and syncs. */
function setupNotion() {
  const ui = SpreadsheetApp.getUi();
  if (!NT_PROPS.getProperty('NOTION_TOKEN')) changeNotionToken();
  if (!NT_PROPS.getProperty('NOTION_DS')) {
    const a = ui.prompt('knowhash → Notion', 'Paste the link to the Notion page your contacts should go in.\n(In Notion: ••• at the top right of the page, then Copy link.)', ui.ButtonSet.OK_CANCEL);
    if (a.getSelectedButton() !== ui.Button.OK) return;
    const m = a.getResponseText().replace(/-/g, '').match(/[0-9a-f]{32}/i);
    if (!m) throw new Error('That doesn\'t look like a Notion page link. Run setupNotion again and paste the page\'s link.');
    const found = findNotionDb_(m[0]);
    const db = found || notionApi_('post', 'databases', {
      parent: { type: 'page_id', page_id: m[0] },
      title: [{ type: 'text', text: { content: NT_DB_TITLE } }],
      initial_data_source: {
        properties: notionSchema_(),
      },
    });
    const ds = (db.data_sources || [])[0];
    if (!ds) throw new Error('Notion ' + (found ? 'found' : 'created') + ' the database but didn\'t say where. Please email support@knowhash.com.');
    NT_PROPS.setProperty('NOTION_DS', ds.id);
    NT_PROPS.setProperty('NOTION_DB_URL', db.url || '');
    // A database we created already has your fields. One we found (e.g. from the template) gets any
    // missing fields added on the first sync, because the saved field list is left empty.
    if (found) NT_PROPS.deleteProperty('NT_FIELDS_SIG');
    else NT_PROPS.setProperty('NT_FIELDS_SIG', JSON.stringify(notionFields_()));
  }
  ScriptApp.getProjectTriggers()
    .filter((t) => t.getHandlerFunction() === 'syncNotion')
    .forEach((t) => ScriptApp.deleteTrigger(t));
  ScriptApp.newTrigger('syncNotion').timeBased().everyMinutes(NT_EVERY_MINUTES).create();
  syncNotion();
  const url = NT_PROPS.getProperty('NOTION_DB_URL');
  ui.alert('knowhash → Notion', 'Connected. Your contacts are in the "' + NT_DB_TITLE + '" database' + (url ? ':\n' + url : '.') + '\n\nNew and changed contacts follow every ' + NT_EVERY_MINUTES + ' minutes.', ui.ButtonSet.OK);
}

/** Looks on your page for a database called "knowhash Contacts" (e.g. from the knowhash Notion
 *  template) and returns it, or null if there isn't one. */
function findNotionDb_(pageId) {
  let cursor;
  do {
    const r = notionApi_('get', 'blocks/' + pageId + '/children?page_size=100' + (cursor ? '&start_cursor=' + cursor : ''));
    const hit = (r.results || []).find((b) => b.type === 'child_database' &&
      String((b.child_database || {}).title || '').trim().toLowerCase() === NT_DB_TITLE.toLowerCase());
    if (hit) return notionApi_('get', 'databases/' + hit.id);
    cursor = r.has_more ? r.next_cursor : null;
  } while (cursor);
  return null;
}

/** Asks for your Notion personal access token and stores it in Script Properties. */
function changeNotionToken() {
  const ui = SpreadsheetApp.getUi();
  const a = ui.prompt('knowhash → Notion', 'Paste your Notion personal access token (it starts ntn_).', ui.ButtonSet.OK_CANCEL);
  if (a.getSelectedButton() !== ui.Button.OK) throw new Error('No token given, so nothing was changed.');
  const token = a.getResponseText().trim();
  if (!/^(ntn_|secret_)/.test(token)) throw new Error('That doesn\'t look like a Notion token. They start ntn_.');
  NT_PROPS.setProperty('NOTION_TOKEN', token);
  notionApi_('get', 'users/me'); // checks the token works
}

/** Sends new and changed Deck contacts to Notion. */
function syncNotion() {
  const ds = NT_PROPS.getProperty('NOTION_DS');
  if (!ds || !NT_PROPS.getProperty('NOTION_TOKEN')) throw new Error('Not set up yet: choose "setupNotion" and click Run.');
  const sheet = SpreadsheetApp.getActive().getSheetByName(NT_TAB);
  if (!sheet) throw new Error('No tab called "' + NT_TAB + '" in this spreadsheet.');

  // Find columns by their header name, and add ours at the far right if they're missing.
  const head = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0].map((h) => String(h).trim());
  [NT_ID, NT_LINK, NT_DONE].forEach((h) => {
    if (head.indexOf(h) >= 0) return;
    if (sheet.getMaxColumns() < head.length + 1) sheet.insertColumnsAfter(sheet.getMaxColumns(), 1);
    sheet.getRange(1, head.length + 1).setValue(h);
    head.push(h);
  });
  const col = {};
  head.forEach((h, i) => { if (h && col[h] == null) col[h] = i; });

  const last = sheet.getLastRow();
  if (last < 2) return;
  const rows = sheet.getRange(2, 1, last - 1, head.length).getDisplayValues();
  const started = Date.now();
  updateNotionFields_(ds);
  addNotionButton_();

  for (let i = 0; i < rows.length; i++) {
    if (Date.now() - started > 5 * 60 * 1000) break; // Apps Script stops at 6 minutes: the rest go on the next run.
    const r = rows[i];
    const v = (k) => (col[k] == null ? '' : String(r[col[k]] || '').trim());
    const rowNo = i + 2;

    if (v('kh_removed').toUpperCase() === 'TRUE') continue;   // removed from Deck: leave Notion alone
    if (!v('kh_name') && !v('kh_email')) continue;
    if (v(NT_ID) === 'deleted') continue;                     // you deleted it in Notion: respect that
    const stamp = v('kh_updated_at') || v('kh_added_at');
    if (v(NT_ID) && stamp && stamp === v(NT_DONE)) continue; // unchanged since the last sync

    // Deck is in charge of these fields. Any other properties you add in Notion are left alone.
    const text = (s) => ({ rich_text: s ? [{ text: { content: s.slice(0, 2000) } }] : [] });
    const email = (s) => ({ email: /^[^@\s]+@[^@\s]+$/.test(s) ? s : null });
    const value = {
      kh_name: { title: [{ text: { content: (v('kh_name') || v('kh_email')).slice(0, 2000) } }] },
      kh_first_name: text(v('kh_first_name')),
      kh_last_name: text(v('kh_last_name')),
      kh_email: email(v('kh_email')),
      kh_other_email: email(v('kh_other_email')),
      kh_phone: { phone_number: v('kh_phone') || null },
      kh_company: text(v('kh_company')),
      kh_headline: text(v('kh_headline')),
      kh_location: text(v('kh_location')),
      kh_profile_url: { url: /^https?:\/\//.test(v('kh_profile_url')) ? v('kh_profile_url') : null },
      kh_connection: { select: v('kh_connection') ? { name: v('kh_connection').replace(/,/g, ' ') } : null },
      kh_notes: text(v('kh_notes')),
      kh_deck_url: { url: deckUrl_(v) || null },
    };
    const properties = {};
    notionFields_().forEach((f) => { properties[f.col === 'kh_name' ? 'title' : f.name] = value[f.col]; });
    // The person's photo as the page icon, the same photo Deck shows.
    const photo = [v('kh_photo_url'), v('gc_photo_url')].find((u) => /^https:\/\//.test(u));
    const icon = photo ? { type: 'external', external: { url: photo } } : undefined;

    try {
      if (v(NT_ID)) {
        try {
          notionApi_('patch', 'pages/' + v(NT_ID), { properties: properties, icon: icon });
        } catch (e) {
          if (/object_not_found|in_trash|archived|trash/i.test(String(e))) {
            sheet.getRange(rowNo, col[NT_ID] + 1).setValue('deleted');
            continue;
          }
          throw e;
        }
      } else {
        const page = notionApi_('post', 'pages', { parent: { type: 'data_source_id', data_source_id: ds }, properties: properties, icon: icon });
        sheet.getRange(rowNo, col[NT_ID] + 1).setValue(page.id);
        sheet.getRange(rowNo, col[NT_LINK] + 1).setValue(page.url);
      }
      sheet.getRange(rowNo, col[NT_DONE] + 1).setValue("'" + stamp); // stored as text, so it compares exactly
      Utilities.sleep(350); // Notion allows about 3 requests a second
    } catch (e) {
      console.warn('Row ' + rowNo + ' (' + v('kh_name') + '): ' + e); // shows under Executions; tried again next run
    }
  }
}

/** The kind of Notion field each knowhash column becomes. */
const NT_TYPES = {
  kh_name: 'title', kh_first_name: 'rich_text', kh_last_name: 'rich_text', kh_email: 'email',
  kh_other_email: 'email', kh_phone: 'phone_number', kh_company: 'rich_text', kh_headline: 'rich_text',
  kh_location: 'rich_text', kh_profile_url: 'url', kh_connection: 'select', kh_notes: 'rich_text', kh_deck_url: 'url',
};

/** The fields you chose in NT_FIELDS (Name is always in). */
function notionFields_() {
  return NT_FIELDS
    .filter((f) => NT_TYPES[f[0]] && (f[2] || f[0] === 'kh_name'))
    .map((f) => ({ col: f[0], name: String(f[1] || '').trim() || f[0], type: NT_TYPES[f[0]] }));
}

/** The database's fields, as Notion wants them. */
function notionSchema_() {
  const out = {};
  notionFields_().forEach((f) => { out[f.name] = { [f.type]: {} }; });
  return out;
}

/** If NT_FIELDS changed since the last run (or you set up with an older copy), add the new fields to Notion. */
function updateNotionFields_(ds) {
  const sig = JSON.stringify(notionFields_());
  if (NT_PROPS.getProperty('NT_FIELDS_SIG') === sig) return;
  const props = {};
  notionFields_().forEach((f) => {
    if (f.type === 'title') props.title = { name: f.name }; // renames the title field; there's only ever one
    else props[f.name] = { [f.type]: {} };                 // adds it, or leaves an existing field as it is
  });
  try {
    notionApi_('patch', 'data_sources/' + ds, { properties: props });
    NT_PROPS.setProperty('NT_FIELDS_SIG', sig);
  } catch (e) {
    console.warn('Could not update the fields in Notion: ' + e); // tried again next run
  }
}

/** Adds an "Open in Notion" button to your Deck cards, once: a row in your sheet's Actions tab.
 *  Rename it or delete it as you like; the script won't put it back. */
function addNotionButton_() {
  const props = PropertiesService.getScriptProperties();
  if (props.getProperty('NT_BUTTON')) return;
  try {
    const ss = SpreadsheetApp.getActive();
    let tab = ss.getSheetByName('Actions');
    if (!tab) {
      tab = ss.insertSheet('Actions');
      tab.getRange(1, 1, 1, 3).setValues([['kh_label', 'kh_url', 'kh_notes']]).setFontWeight('bold');
    }
    const vals = tab.getDataRange().getValues();
    const head = vals[0].map((h) => String(h).trim().toLowerCase());
    const L = head.indexOf('kh_label'), U = head.indexOf('kh_url'), N = head.indexOf('kh_notes');
    if (L < 0 || U < 0) { props.setProperty('NT_BUTTON', 'skipped'); return; } // tab changed by hand: leave it alone
    if (!vals.slice(1).some((r) => /\{nt_link\}/i.test(String(r[U])))) {
      const row = head.map(() => '');
      row[L] = 'Open in Notion';
      row[U] = '{nt_link}';
      if (N >= 0) row[N] = 'Added by the knowhash Notion script. Rename or delete it as you like.';
      tab.appendRow(row);
    }
    props.setProperty('NT_BUTTON', 'yes');
  } catch (e) {
    console.warn('Could not add the Open in Notion button: ' + e); // tried again next run
  }
}

/** A link to this person's card in your Deck: knowhash's kh_deck_url column, or built the same way. */
function deckUrl_(v) {
  if (/^https:\/\//.test(v('kh_deck_url'))) return v('kh_deck_url');
  const m = v('kh_profile_url').match(/linkedin\.com\/in\/([^/?#]+)/i);
  if (!m) return '';
  let key = m[1];
  try { key = decodeURIComponent(key); } catch (e) {}
  return 'https://knowhash.com/deck/?s=' + encodeURIComponent(SpreadsheetApp.getActive().getId()) + '#c=' + encodeURIComponent(key.toLowerCase());
}

/** One call to the Notion API, waiting and retrying once if Notion says to slow down. */
function notionApi_(method, path, body) {
  const opts = {
    method: method,
    contentType: 'application/json',
    headers: { Authorization: 'Bearer ' + NT_PROPS.getProperty('NOTION_TOKEN'), 'Notion-Version': NT_VERSION },
    muteHttpExceptions: true,
  };
  if (body) opts.payload = JSON.stringify(body);
  for (let attempt = 0; attempt < 2; attempt++) {
    const res = UrlFetchApp.fetch(NT_API + path, opts);
    const code = res.getResponseCode();
    if (code === 429 && attempt === 0) {
      Utilities.sleep(1000 * (Number(res.getHeaders()['Retry-After']) || 2));
      continue;
    }
    const out = JSON.parse(res.getContentText() || '{}');
    if (code >= 300) {
      if (code === 401) throw new Error('Notion didn\'t accept your token (it may have expired). Run "changeNotionToken" and paste a new one.');
      throw new Error('Notion ' + code + ' ' + (out.code || '') + ': ' + (out.message || res.getContentText()));
    }
    return out;
  }
}

Script version 2026-12-03. It's also on the second line of the script, so you can check which copy you have.

The two scripts sit happily side by side: every name in this one starts with Notion or NT_.

Step 4: Run setupNotion

  1. In the toolbar, choose setupNotion from the function list, then click Run.
  2. Google asks for permission. Click Review permissions and choose your account. You'll see Google hasn't verified this app: that's normal for your own script. Click Advanced, then Go to … (unsafe), then Continue. (The Google Contacts guide has pictures of these screens.)
  3. Now switch to your sheet's tab. The script waits there, not in Apps Script, for you to paste your token, then your page's link.
A box in the Google Sheet titled knowhash → Notion asking for the Notion personal access token

The boxes appear in your sheet, not in Apps Script.

A moment later, the script confirms it's connected and gives the link to your new knowhash Contacts database.

Box in the sheet: Connected. Your contacts are in the knowhash Contacts database, with its link, and new and changed contacts follow every 15 minutes

Your contacts are already in Notion, and three columns have appeared at the far right of your Contacts tab: nt_id, nt_link and nt_synced. Leave them to the script.

The knowhash Contacts database in Notion with contacts, companies and emails, each with their photo as the page icon

Your Deck in Notion. Add views, filters and your own properties as you like.

Step 5: Your Open in Notion button

There's nothing to add: the script puts an Open in Notion row in your sheet's Actions tab for you (and makes the tab if you don't have one). Back in Deck, tap Refresh. Each card now has the button. On your phone it opens the Notion app if you have it, or Notion in the browser (sign in once).

Rename or delete the row in the Actions tab as you like; the script won't put it back.

Deck card on a phone with an Open in Notion button
Open in Notion on the Deck card…
The same contact's Notion page on a phone, with photo, company, headline, LinkedIn link, status and notes
…opens their Notion page, photo and all.

That's it

Add or edit someone in Deck, and within 15 minutes their Notion page is created or updated. Can't wait? In Apps Script, choose syncNotion and click Run.

Deck is in charge of the fields you chose (all thirteen unless you changed them in step 3), including knowhash Deck, a link back to the person's Deck card. If you edit Email or Headline in Notion, the next change in Deck puts Deck's value back. Add your own properties for anything else, such as Stage, Tags or Next step: the script never touches them.

Deleted someone in Notion? The script marks them deleted in nt_id and leaves them alone. To send them again, clear their nt_id cell.

Tip: photos for everyone. Pages get a photo when Deck has one. Also send your Deck to Google Contacts, and people with a Google profile photo get it on their Deck card and their Notion page.

If something doesn't work

  • Stuck on "Execution started": the script is waiting for you in your sheet's tab. Switch to it and paste your token. A run left waiting stops by itself after 6 minutes.
  • "Identifier has already been declared": you have an older copy of this script, or another script uses the same names. Copy the script from this page again.
  • "Notion didn't accept your token": it was mistyped, revoked or has expired. Make a new one (step 2), then in Apps Script choose changeNotionToken, click Run, and paste it in your sheet.
  • "That doesn't look like a Notion page link": copy the link with the link icon at the top right of the page, and run setupNotion again.
  • No Open in Notion button: that contact hasn't reached Notion yet, or Deck is showing what it loaded earlier. Tap Refresh at the bottom of the Deck card.
  • A contact didn't arrive: in Apps Script, click Executions (the list icon on the left) to see what happened. Contacts that fail are tried again on the next run.
  • Want it in a different page? Move the knowhash Contacts database anywhere in Notion. The script keeps working.

Improve this guide. Did a screen look different, a step trip you up, or would you like it to do more? Tell us, and we'll update the guide for everyone who uses it next.


Would rather we set this up for you? Email Mike. Questions? support@knowhash.com · All connection guides