From a4bfa7dd053779367e3f8152807b8cd9d4b7f563 Mon Sep 17 00:00:00 2001 From: Ian Cooperman Date: Mon, 1 Aug 2022 19:00:19 -0700 Subject: [PATCH] Began work on interfacing with the Joplin Data API --- joplin.js | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/joplin.js b/joplin.js index a77b8f6..9b2aa95 100644 --- a/joplin.js +++ b/joplin.js @@ -1,8 +1,33 @@ -import fetch from 'node-fetch'; +import fetch from 'node-fetch' +import 'dotenv/config' -async function main() { - const res = await fetch("https://example.com"); - console.log(res.body); +let url = new URL("http://localhost:" + process.env.JOPLIN_CLIPPER_PORT + "/notes") +url.searchParams.append("token", process.env.JOPLIN_TOKEN) + + +async function getNotes(notebookID) { + let foldersURL = new URL("http://localhost:" + process.env.JOPLIN_CLIPPER_PORT + "/folders/" + process.env.JOPLIN_NOTEBOOK_ID + "/notes") + + foldersURL.searchParams.append("token", process.env.JOPLIN_TOKEN) + + const res = await fetch(foldersURL.href) + const data = await res.json() + + return data } -const res = main(); \ No newline at end of file +async function getNoteData(noteID) { + let noteURL = new URL("http://localhost:" + process.env.JOPLIN_CLIPPER_PORT + "/notes/" + noteID) + + const res = await fetch(noteURL.href) + const data = await res.json() + + return data +} + +getNotes() + .then(res => { + res.items.forEach(element => { + console.log(element.id) + }); + }) \ No newline at end of file