Skip to content

Commit 8a135da

Browse files
committed
Update for new Todoist API and cleanup
1 parent c40d16f commit 8a135da

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

dbludeau.TodoistNoteplanSync/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
See Plugin [README](https://github.com/NotePlan/plugins/blob/main/dbludeau.TodoistNoteplanSync/README.md) for details on available commands and use cases.
66

7+
## [0.4.0] - 2025-09-15 (dbludeau)
8+
- Updated plugin to use new Todoist V1 API.
9+
710
## [0.3.0] - 2024-09-01 (dbludeau)
811
- Fixed issue caused by "Folder" setting for Sync Everything command.
912
- If leading or trailing slash was included, the plugin would not recognize the folder as already existing, leading to duplication of notes.

dbludeau.TodoistNoteplanSync/src/NPPluginMain.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { getTodaysDateAsArrowDate, getTodaysDateUnhyphenated } from '../../helpe
3434
import pluginJson from '../plugin.json'
3535
import { log, logInfo, logDebug, logError, logWarn, clo, JSP } from '@helpers/dev'
3636

37-
const todo_api: string = 'https://api.todoist.com/rest/v2'
37+
const todo_api: string = 'https://api.todoist.com/api/v1'
3838

3939
// set some defaults that can be changed in settings
4040
const setup: {
@@ -350,12 +350,12 @@ async function syncTodayTasks() {
350350
const response = await pullTodoistTasksForToday()
351351
const tasks: Array<Object> = JSON.parse(response)
352352

353-
if (tasks.length > 0 && note) {
354-
for (let i = 0; i < tasks.length; i++) {
355-
await writeOutTask(note, tasks[i])
356-
}
353+
if (tasks.results && note) {
354+
tasks.results.forEach(async (t) => {
355+
await writeOutTask(note, t)
356+
})
357357

358-
//close the tasks in Todoist if they are complete in Noteplan`
358+
// close the tasks in Todoist if they are complete in Noteplan`
359359
closed.forEach(async (t) => {
360360
await closeTodoistTask(t)
361361
})
@@ -371,13 +371,12 @@ async function syncTodayTasks() {
371371
* @returns {Promise<void>}
372372
*/
373373
async function projectSync(note: TNote, id: string): Promise<void> {
374-
console.log(`ID is ${id}`)
375374
const task_result = await pullTodoistTasksByProject(id)
376-
console.log(task_result)
377375
const tasks: Array<Object> = JSON.parse(task_result)
378-
for (let j = 0; j < tasks.length; j++) {
379-
await writeOutTask(note, tasks[j])
380-
}
376+
377+
tasks.results.forEach(async (t) => {
378+
await writeOutTask(note, t)
379+
})
381380
}
382381

383382
/**
@@ -492,7 +491,7 @@ function formatTaskDetails(task: Object): string {
492491
task_write = `${priorities}${task.content}`
493492

494493
// add the Todoist URL to the end of the string
495-
task_write = `${task_write}[^](${task.url})`
494+
task_write = `${task_write}[^](https://app.todoist.com/app/task/${task.id})`
496495

497496
// add the lables after the URL
498497
if (setup.addTags) {
@@ -576,8 +575,9 @@ async function writeOutTask(note: TNote, task: Object) {
576575
section = JSON.parse(section)
577576
if (section) {
578577
if (!existing.includes(task.id) && !just_written.includes(task.id)) {
579-
logInfo(pluginJson, `Task will be added Noteplan (${task.id})`)
578+
logInfo(pluginJson, `1. Task will be added to ${note.title} below ${section.name} (${formatted})`)
580579
note.addTodoBelowHeadingTitle(formatted, section.name, true, true)
580+
581581
// add to just_written so they do not get duplicated in the Today note when updating all projects and today
582582
just_written.push(task.id)
583583
} else {
@@ -588,28 +588,31 @@ async function writeOutTask(note: TNote, task: Object) {
588588
// Put it in with no heading
589589
logWarn(pluginJson, `Section ID ${task.section_id} did not return a section name`)
590590
if (!existing.includes(task.id) && !just_written.includes(task.id)) {
591-
logInfo(pluginJson, `Task will be added to Noteplan (${task.id})`)
591+
logInfo(pluginJson, `2. Task will be added to ${note.title} (${formatted})`)
592592
note.appendTodo(formatted)
593+
593594
// add to just_written so they do not get duplicated in the Today note when updating all projects and today
594595
just_written.push(task.id)
595596
} else {
596-
logInfo(pluginJson, `Task is already in Noteplan (${task.id})`)
597+
logInfo(pluginJson, `Task is already in Noteplan (${formatted})`)
597598
}
598599
}
599600
} else {
600601
// check for a default heading
601602
// if there is a predefined header in settings
602603
if (setup.header !== '') {
603604
if (!existing.includes(task.id) && !just_written.includes(task.id)) {
604-
logInfo(pluginJson, `Adding task from Todoist to Note`)
605-
note?.addTodoBelowHeadingTitle(formatted, setup.header, true, true)
605+
logInfo(pluginJson, `3. Task will be added to ${note.title} below ${setup.header} (${formatted})`)
606+
note.addTodoBelowHeadingTitle(formatted, setup.header, true, true)
607+
606608
// add to just_written so they do not get duplicated in the Today note when updating all projects and today
607609
just_written.push(task.id)
608610
}
609611
} else {
610612
if (!existing.includes(task.id) && !just_written.includes(task.id)) {
611-
logInfo(pluginJson, `Task will be added to Noteplan (${task.id})`)
613+
logInfo(pluginJson, `4. Task will be added to ${note.title} (${formatted})`)
612614
note.appendTodo(formatted)
615+
613616
// add to just_written so they do not get duplicated in the Today note when updating all projects and today
614617
just_written.push(task.id)
615618
}

0 commit comments

Comments
 (0)