Doist / todoist-python

DEPRECATED The official Todoist Python API library
MIT License
533 stars 73 forks source link

Sub-tasks made with parent-ids don't appear as subtask on other todoist services #24

Closed tomsdalton closed 7 years ago

tomsdalton commented 7 years ago

Hi,

Having issues creating subtasks, code example at bottom.

A task is updated to have parent_id of desired parent task. When persisted the subtask does not appear as a subtask on other todoist services. When subtask is retrieved again through the api, interrogating the JSON shows the task still has the parent_id set correctly.

Interestingly, if the task is made into a subtask through another todoist service (e.g. todoist.com) the JSON retrieved by the api is the same as that for the subtask made through the api - however the api made subtask does not appear as a subtask on other todoist services.

Thanks for your time, Tom

`

import todoist

if __name__ == '__main__':

    # Login

    api = todoist.TodoistAPI()
    user = api.user.login('user', 'secret')
    response = api.sync()

    projectId = None

    for p in response['projects']:
        if p['name'] == 'Home':
            projectId = p['id']

    # Make tasks

    aTask = api.items.add('A', projectId)
    bTask = api.items.add('B', projectId)

    # Make B subtask of A

    bTask.update(parent_id=aTask['id'])

    # Sync

    api.commit()
    response = api.sync()

    # Get latest versions of tasks from server

    aTask = api.items.get_by_id(aTask['id'])
    bTask = api.items.get_by_id(bTask['id'])

    print aTask
    print '\n'
    print bTask

`

rohitpaulk commented 7 years ago

I can confirm this behaviour, screenshots below:

Script output: (I added a few lines to debug)

actual

How it looks on todoist.com:

todoist_expected

rohitpaulk commented 7 years ago

Looking through the docs, I don't see a mention of parent_id as a parameter at all 🤔

There is a parameter named indent though - looks like it is related.

The indent of the task (a number between 1 and 4, where 1 is top-level).

rohitpaulk commented 7 years ago

Using indent seemed to work.

I replaced bTask.update(parent_id=aTask['id']) with bTask.update(indent=2). parent_id is returned as null, but it renders properly on Todoist.com:

screen shot 2017-05-11 at 4 19 38 am

rohitpaulk commented 7 years ago

Interestingly, if the task is made into a subtask through another todoist service (e.g. todoist.com) the JSON retrieved by the api is the same as that for the subtask made through the api - however the api made subtask does not appear as a subtask on other todoist services.

My guess is that parent_id was deprecated in favor of indent, and that the web version sends both parameters (maybe part of a backward-compatible/parallel change). That should explain the above.

lefcha commented 7 years ago

The current way of figure out the tasks and sub-tasks hierarchy is by using the item_order and indent properties of item objects inside each project. The first orders the items from 1, 2, and up to the last, while the indent adds indentation to a task to make it a sub-task of the task that is above it and has a lower indent level.

Imagine these tasks, and observe the values of the aforementioned properties inside the parentheses:

- A (1, 1)
- B (2, 1)
  - C (3, 2)
    - D (4, 3)
  - E (5, 2)
-F (6, 1)

Now the parent_id is an experimental property, that only some of our clients are using, as we try to simplify the above scheme. You shouldn't rely on it, or actually pay any attention to it at the moment.

We will probably look into hiding it somehow for other users of our API, until we have something solid, that can be used by everyone.

Hope this clears things up.