Adjusted getNotesFromNotebook() to also take the fields to retrive

This commit is contained in:
Ian Cooperman 2022-08-04 15:16:02 -07:00
parent aab9cada6d
commit e5d4bdf90d

View File

@ -1,14 +1,16 @@
import fetch from 'node-fetch'
import 'dotenv/config'
let url = new URL("http://localhost:" + process.env.JOPLIN_CLIPPER_PORT + "/notes")
url.searchParams.append("token", process.env.JOPLIN_TOKEN)
//This function gets notes from a specified notebook, using the notebook's ID. The fields parameter specifies which fields to include in the response.
// @param {string=} notebookID - The id of the notebook you want to get notes from, as extracted from the notebook's external link
// @param {Array[string]=} fields - The specific fields wanted in the returned response. Valid fields can be found in this table: https://joplinapp.org/api/references/rest_api/#properties
async function getNotesFromNotebook(notebookID, fields) {
const fieldsString = fields.join()
async function getNotesFromNotebook(notebookID) {
let foldersURL = new URL("http://localhost:" + process.env.JOPLIN_CLIPPER_PORT + "/folders/" + process.env.JOPLIN_NOTEBOOK_ID + "/notes")
let foldersURL = new URL("http://localhost:" + process.env.JOPLIN_CLIPPER_PORT + "/folders/" + notebookID + "/notes")
foldersURL.searchParams.append("token", process.env.JOPLIN_TOKEN)
foldersURL.searchParams.append("fields", "id,title,body,created_time,updated_time,latitude,longitude,altitude,is_todo,todo_due,todo_completed")
foldersURL.searchParams.append("fields", fieldsString)
const res = await fetch(foldersURL.href)
const data = await res.json()
@ -16,5 +18,5 @@ async function getNotesFromNotebook(notebookID) {
return data
}
getNotesFromNotebook()
getNotesFromNotebook(process.env.JOPLIN_NOTEBOOK_ID, ["id", "title", "body", "created_time", "latitude", "longitude", "altitude", "is_todo", "todo_due", "todo_completed"])
.then(res => console.log(res))