Giter VIP home page Giter VIP logo

node-todoist's Introduction

Todoist

npm version

This module implements v9 of Todoist Sync API described here

Installation

npm install todoist

or

yarn add todoist

Usage

const Todoist = require('todoist').v9
const todoist = Todoist(process.env.TODOIST_API_KEY)

;(async () => {
  // READING DATA:
  // sync(): retrieves the latest data, incrementally.
  //         the first call retrieves all data, but you can ask
  //         for the specific data you want by passing
  //         eg ['projects', 'items']
  await todoist.sync()

  // todoist.xxxxxx.get() functions are not async functions,
  // they return the data that was already fetched by .sync()
  const items = todoist.items.get()

  // WRITING DATA:
  // the rest of the functions require arguments, refer to the offical
  // doc for details
  const newItem = await todoist.items.add({ content: 'new task!' })

  // all functions (except .get()) perform a sync before resolving,
  // therefore if you call .get() again you get the most up-to-date data
})()

API token available here: https://todoist.com/prefs/integrations

API

The API is derived directly from the official documentation. It is transcribed below because the code is so simple to read it's better this way:

function sync(resourceTypes = ['all']) {
  /* ... */
}

const projects = {
  get: () => state.projects,
  add: createCommand < Types.ProjectAdd > ('project', 'add'),
  update: createCommand < Types.ProjectUpdate > ('project', 'update'),
  move: createCommand < Types.ProjectMove > ('project', 'move'),
  delete: createCommand < Types.ProjectDelete > ('project', 'delete'),
  archive: createCommand < Types.ProjectArchive > ('project', 'archive'),
  unarchive: createCommand < Types.ProjectUnarchive > ('project', 'unarchive'),
  reorder: createCommand < Types.ProjectReorder > ('project', 'reorder'),
}

const items = {
  get: () => state.items,
  add: createCommand < Types.ItemAdd > ('item', 'add'),
  update: createCommand < Types.ItemUpdate > ('item', 'update'),
  move: createCommand < Types.ItemMove > ('item', 'move'),
  reorder: createCommand < Types.ItemReorder > ('item', 'reorder'),
  delete: createCommand < Types.ItemDelete > ('item', 'delete'),
  close: createCommand < Types.ItemClose > ('item', 'close'),
  complete: createCommand < Types.ItemComplete > ('item', 'complete'),
  uncomplete: createCommand < Types.ItemUncomplete > ('item', 'uncomplete'),
  archive: createCommand < Types.ItemArchive > ('item', 'archive'),
  unarchive: createCommand < Types.ItemUnarchive > ('item', 'unarchive'),
  updateDayOrders: createCommand < Types.ItemUpdateDayOrders > ('item', 'update_day_orders'),
  updateDateCompleted: createCommand < Types.ItemUpdateDateComplete > ('item', 'update_date_complete'),
}

const labels = {
  get: () => state.labels,
  add: createCommand < Types.LabelAdd > ('label', 'add'),
  update: createCommand < Types.LabelUpdate > ('label', 'update'),
  delete: createCommand < Types.LabelDelete > ('label', 'delete'),
  updateOrders: createCommand < Types.LabelUpdateOrders > ('label', 'update_orders'),
}

const notes = {
  get: () => state.notes,
  add: createCommand < Types.NoteAdd > ('note', 'add'),
  update: createCommand < Types.NoteUpdate > ('note', 'update'),
  delete: createCommand < Types.NoteDelete > ('note', 'delete'),
}

const projectNotes = {
  get: () => state.project_notes,
  add: createCommand < Types.ProjectNoteAdd > ('project_note', 'add'),
  update: createCommand < Types.ProjectNoteUpdate > ('project_note', 'update'),
  delete: createCommand < Types.ProjectNoteDelete > ('project_note', 'delete'),
}

const sections = {
  get: () => state.sections,
  add: createCommand < Types.SectionAdd > ('section', 'add'),
  update: createCommand < Types.SectionUpdate > ('section', 'update'),
  move: createCommand < Types.SectionMove > ('section', 'move'),
  reorder: createCommand < Types.SectionReorder > ('section', 'reorder'),
  delete: createCommand < Types.SectionDelete > ('section', 'delete'),
  archive: createCommand < Types.SectionArchive > ('section', 'archive'),
  unarchive: createCommand < Types.SectionUnarchive > ('section', 'unarchive'),
}

const filters = {
  get: () => state.filters,
  add: createCommand < Types.FilterAdd > ('filter', 'add'),
  update: createCommand < Types.FilterUpdate > ('filter', 'update'),
  delete: createCommand < Types.FilterDelete > ('filter', 'delete'),
  updateOrders: createCommand < Types.FilterUpdateOrders > ('filter', 'update_orders'),
}

const reminders = {
  get: () => state.reminders,
  add: createCommand < Types.ReminderAdd > ('reminder', 'add'),
  update: createCommand < Types.ReminderUpdate > ('reminder', 'update'),
  delete: createCommand < Types.ReminderDelete > ('reminder', 'delete'),
  clearLocations: createCommand < Types.ReminderClearLocations > ('reminder', 'clear_locations'),
}

const user = {
  get: () => state.user,
  update: createCommand < Types.UserUpdate > ('user', 'update'),
  updateGoals: createCommand < Types.UserUpdateGoals > ('user', 'update_goals'),
}

const settings = {
  get: () => state.user_settings,
  update: createCommand < Types.UserSettingsUpdate > ('user_settings', 'update'),
}

const sharing = {
  collaborators: () => state.collaborators,
  shareProject: createCommand < Types.CollaboratorShareProject > ('collaborator', 'share_project'),
  deleteCollaborator: createCommand < Types.CollaboratorDeleteCollaborator > ('collaborator', 'delete_collaborator'),
  acceptInvitation: createCommand < Types.CollaboratorAcceptInvitation > ('collaborator', 'accept_invitation'),
  rejectInvitation: createCommand < Types.CollaboratorRejectInvitation > ('collaborator', 'reject_invitation'),
  deleteInvitation: createCommand < Types.CollaboratorDeleteInvitation > ('collaborator', 'delete_invitation'),
}

const liveNotifications = {
  setLastRead: createCommand < Types.LiveNotificationsSetLastRead > ('live_notifications', 'set_last_read'),
  markAsRead: createCommand < Types.LiveNotificationsMarkRead > ('live_notifications', 'mark_read'),
  markAllAsRead: createCommand < Types.LiveNotificationsMarkReadAll > ('live_notifications', 'mark_read_all'),
  markAsUnread: createCommand < Types.LiveNotificationsMarkUnread > ('live_notifications', 'mark_unread'),
}

const business = {
  // TODO: implement
}

const activityLog = {
  get: (options: any) => request({ url: `${options.endpoint}/activity/get`, query: options }),
}

const backup = {
  // TODO: implement
}

const email = {
  // TODO: implement
}

const api = {
  activityLog,
  backup,
  business,
  colorsById: COLORS_BY_ID,
  commit,
  email,
  filters,
  items,
  labels,
  liveNotifications,
  notes,
  projects,
  projectNotes,
  reminders,
  sections,
  settings,
  sharing,
  state,
  sync,
  user,
}

Closing note on efficiency

This module is not using the Sync API to it's full capacity. It is possible to issue multiple commands in a single request, but this module doesn't.

For most cases, it doesn't matter. However if it does for you please file an issue: https://github.com/romgrk/node-todoist/issues

node-todoist's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-todoist's Issues

No completed items?

Heyo, great module!

Sync doesn't seem to grab completed items. Is there an option for this I'm missing?

Way to incrementally sync without keeping process running

I want to use the incremental sync feature of the todoist API.
It looks like this library support you calling sync() multiple times on the same Todoist object, each time getting only the data that changed.

I'd like to use incremental sync in a serverless function (e.g. lambda function) where no state (no Todoist object) is being saved between calls to sync(). Is this supported?

batch commits

Hi all,

First of all ... what an excellent module, everybody!
Thanks for your hard work!

However, in my project I will often need to update a lot of tasks at once. Because of that, batching multiple commands would probably provide a better experience. I saw your comment on the README.md about this, and I was wondering whether you are considering adding this functionality.

Kind regards,
P

Confusion with types (typescript)

Hi, trying to use your library and having difficulties with return type

  • Version - 0.5.1

For example, trying to add task

items: {
...
add: (args: TodoistV8Types.ItemAdd) => Promise<TodoistV8Types.NodeType | undefined>;
...
}

It returns TodoistV8Types.NodeType, but i except to get TodoistV8Types.Item with result from response to update my locale store with new task

Data returned from request:
image

Request:
image

Can you explain why the type is returned everywhere equals to NodeType?

HTTPError: Response code 403 (Forbidden)

Just installed the npm module, added my API key and ran the example provided in the readme.

Whatever I tried to do I receive a HTTPError: Response code 403 (Forbidden) error.

specifying project_id for a new task - number vs string?

Hello there,

I just tried your API shell because I am trying to save time :) So thank you.

Problem is when I try to add an item and specify the project_id via a variable it somehow gets ignored. When I type it up manually (the actual digits), it goes to the right project id. Does the variable get truncated somewhere? Digits added? changed? 0s removed? switches from number type to string type? I can't figure out what is going on and have no clue how to debug.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.