Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
reMarkable to Notion Sync
const GMAIL_LABEL_NAME = 'NotionToSync';
const SYNCED_LABEL = 'SyncedToNotion';
const gmailToNotion = () => {
const label = GmailApp.getUserLabelByName(GMAIL_LABEL_NAME);
const successLabel = GmailApp.getUserLabelByName(SYNCED_LABEL);
label.getThreads(0, 20).forEach((thread) => {
const [message] = thread.getMessages().reverse();
postToNotion(message);
thread.removeLabel(label);
thread.addLabel(successLabel)
});
};
function postToNotion(message) {
const url = 'https://api.notion.com/v1/pages';
const body = {
parent: {
type: "database_id",
database_id: "<Your Target Notion Database Id>",
},
icon: {
type: "emoji",
emoji: "📝"
},
children: [
{
object: 'block',
type: 'paragraph',
paragraph: {
rich_text: [
{
type: 'text',
text: {
content: message.getPlainBody()
},
},
],
},
}
],
properties: {
Name: {
title: [
{
text: {
content: message.getSubject(),
},
},
],
}
}
}
UrlFetchApp.fetch(url, {
method: 'post',
contentType: "application/json",
muteHttpExceptions: false,
headers: {
Authorization: `Bearer <Your Notion Secret>`,
'Notion-Version': '2022-02-22'
},
payload: JSON.stringify(body)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment