Your own Roam Research Quicknote REST API with Firebase
Tags: nocode, roamresearch, firebase, ios
Published: 2022-01-13 18:55:42

---
title: Your own Roam Research Quicknote REST API with Firebase
published: true
date: 2022-01-13 18:33:02 UTC
tags: Nocode,RoamResearch,Firebase,iOS
canonical_url: https://piszek.com/2022/01/13/firebase2roam/
---
I love Roam Research ([have written a lot about it](https://piszek.com/roam/)), but the biggest struggle for me is the lack of the proper REST API. I have tried [faking it with Puppeteer](https://piszek.com/roam/roam-api/), but I needed something quick for capturing the notes on the go.

Now I can capture the notes from a variety of apps through IFTTT, or iOS shortcuts (including Siri on my watch), and I have been doing so for more than a year. [As automation is important for me](https://piszek.com/2019/11/14/y-u-bots/), this script has helped include roam into my workflows.

> Hey Siri, make a note in Roam
> 
> <cite>Cool, huh?</cite>

[![](https://i0.wp.com/piszek.com/wp-content/uploads/2022/01/Zrzut-ekranu-2022-01-13-o-19.22.43.png?resize=620%2C181&ssl=1)](https://i0.wp.com/piszek.com/wp-content/uploads/2022/01/Zrzut-ekranu-2022-01-13-o-19.22.43.png?ssl=1)

## How does it work?

1. iOS shortcut or IFTTT makes a POST request to Firebase DB
2. Every 10 minutes Roam checks that DB, fetches new notes and deletes them in DB.
3. Any new note shows up in my current daily page, with “_#Inbox_” tag

From what I have been able to gather, this is similar to what [phonetonote](https://phonetonote.com/) is doing, without the need for you to manage your own DB.

## What do you need to make this work for you?

You need 3 things: A Firebase project, a custom script in your Roam graph, and iOS shortcuts to start getting your data in the graph.

### Firebase

Firebase is a Google Cloud offering that lets you store JSON in the cloud. With the usage you will be generating, you will be able to operate the project for free.

1. You need to set up a [Firebase Realtime Database](https://firebase.google.com/products/realtime-database) project
2. Once you set it up, you need to generate a database secret ( Project Settings -> Service Accounts -> Database Secrets)

[![](https://i0.wp.com/piszek.com/wp-content/uploads/2022/01/Zrzut-ekranu-2022-01-13-o-18.56.24.png?resize=620%2C400&ssl=1)](https://i0.wp.com/piszek.com/wp-content/uploads/2022/01/Zrzut-ekranu-2022-01-13-o-18.56.24.png?ssl=1)

### Roam custom plugin

This custom Roam plugin will pull data from this database – you can customize `path/to/quicknotes` to whatever you like.

[Read here on how to install custom Roam plugins](https://piszek.com/roam/roam-plugins/)

```
const fireBaseUrl = 'https://YOURPROJECT.firebaseio.com/path/to/quicknotes';
const fireBaseToken = '';

function zeroPad( data ) {
	if ( data < 10 ) {
		return '0' + data;
	}
	return '' + data;
}

function getTodayUid() {
	const d = new Date();
	return zeroPad( d.getMonth() + 1 ) + "-" + zeroPad( d.getDate() ) + "-" + d.getFullYear();
}
function importFromFirebase() {
	window.fetch( fireBaseUrl + '.json?auth=' + fireBaseToken )
		.then( response => response.json() )
		.then( data => {
			console.log( 'Firebase Import:', data );
			if ( ! data ) {
				return;
			}
			Object.keys( data ).forEach( key => {
				const entry = data[key];
				if ( ! entry.string ) {
					console.warn( 'The payload needs at least a string', entry );
					return;
				}
                entry.string += ' #Inbox';
				window.roamAlphaAPI.createBlock( {
					"location": {"parent-uid": getTodayUid(), "order": 0 }, 
					"block": entry
				} );
				window.fetch( fireBaseUrl + '/' + key + '.json?auth=' + fireBaseToken, { method: 'DELETE' } );
			} );
		} );
  
	window.setTimeout( importFromFirebase, 10 * 60 * 1000 ); // Check for more notes every 10 minutes.
}

window.setTimeout( importFromFirebase, 60 * 1000 ); // We run this a minute after Roam starts.
```

### Start POSTing your data

Now you need to start throwing your data into the database and see it in your Roam graph!

#### iOS shortcuts

Here is an iOS shortcut action that will save my data in this database. You can include it in your workflows (just remember to change Text to your token and YOURPROJECT to your project).

[![](https://i0.wp.com/piszek.com/wp-content/uploads/2022/01/IMG_5390.jpg?resize=620%2C876&ssl=1)](https://i0.wp.com/piszek.com/wp-content/uploads/2022/01/IMG_5390.jpg?ssl=1)

#### IFTTT

You can always include it in [IFTTT](https://ifttt.com) to provide similar functionality, or make it save all your liked Youtube videos for example:

[![](https://i0.wp.com/piszek.com/wp-content/uploads/2022/01/Zrzut-ekranu-2022-01-13-o-19.10.00.png?resize=620%2C519&ssl=1)](https://i0.wp.com/piszek.com/wp-content/uploads/2022/01/Zrzut-ekranu-2022-01-13-o-19.10.00.png?ssl=1)

[![](https://i0.wp.com/piszek.com/wp-content/uploads/2022/01/Zrzut-ekranu-2022-01-13-o-19.11.04.png?resize=601%2C1024&ssl=1)](https://i0.wp.com/piszek.com/wp-content/uploads/2022/01/Zrzut-ekranu-2022-01-13-o-19.11.04.png?ssl=1)

**Enjoy!**