pythontodoist

Why is this weird ID returned when using todoist python api?


This question is regarding the use of todoist python api.

After adding an item (that's what a task is called in the api) I get these weird looking IDs. I say weird because a regular id is just an integer. But these IDs are not usable in anyway, I can't do api.items.get_by_id() with this id. What is going on? How do I get out from this weird state?

'reply email': 'b5b4eb2c-b28f-11e9-bd8d-80e6500af142',

I printed out a few more IDs, and all the integer ones work well with all API calls, the UUID ones throw an exception.

3318771761
3318771783
3318771807
3318771823
3318771843
61c30a10-b2a0-11e9-98d7-80e6500af142
62326586-b2a0-11e9-98d7-80e6500af142
62a3ea9e-b2a0-11e9-98d7-80e6500af142
631222ac-b2a0-11e9-98d7-80e6500af142
63816338-b2a0-11e9-98d7-80e6500af142
63efd14c-b2a0-11e9-98d7-80e6500af142

Solution

  • You have to use api.commit() to do the Sync and have the final id. The id you're trying to use is just a temporary id while the sync is not done.

    >>> import todoist; import os; token = os.environ.get('token'); api = todoist.TodoistAPI(token); item=api.items.add('test');
    
    >>> item
    Item({'content': 'test',
     'id': '3b4d77c0-b891-11e9-a080-2afbabeedbe3',
     'project_id': 1490600000})
    
    >>> api.commit()
    {'full_sync': False, 'sync_status': {'3b4d793c-b891-11e9-a080-2afbabeaeaef': 'ok'}, 'temp_id_mapping': {'3b4d77c0-b891-11e9-a080-2afbabeaeaef': 3331113774}, 'labels': [], 'project_notes': [], 'filters': [], 'sync_token': 'EEVprctG1E39VDqJfu_cwyhpO6rkOaavyU5r70Eu0nY1ZjsWSjssGr4qLLLikucJAu_Zakld7DniBsEyZ7i820dqcZNcOAbUcbzHFpMpSjzr-GALTA', 'day_orders': {}, 'projects': [], 'collaborators': [], 'day_orders_timestamp': '1564672738.25', 'live_notifications_last_read_id': 2259500000, 'items': [{'legacy_project_id': 1484800000, 'day_order': -1, 'assigned_by_uid': 5050000, 'labels': [], 'sync_id': None, 'section_id': None, 'in_history': 0, 'child_order': 3, 'date_added': '2019-08-06T21:29:18Z', 'id': 3331113774, 'content': 'test2', 'checked': 0, 'user_id': 5050000, 'due': None, 'priority': 1, 'parent_id': None, 'is_deleted': 0, 'responsible_uid': None, 'project_id': 1490600000, 'date_completed': None, 'collapsed': 0}], 'notes': [], 'reminders': [], 'due_exceptions': [], 'live_notifications': [], 'sections': [], 'collaborator_states': []}
    
    >>> item
    Item({'assigned_by_uid': 5050000,
     'checked': 0,
     'child_order': 3,
     'collapsed': 0,
     'content': 'test',
     'date_added': '2019-08-06T21:29:18Z',
     'date_completed': None,
     'day_order': -1,
     'due': None,
     'id': 3331100000,
     'in_history': 0,
     'is_deleted': 0,
     'labels': [],
     'legacy_project_id': 148400000,
     'parent_id': None,
     'priority': 1,
     'project_id': 1490660000,
     'responsible_uid': None,
     'section_id': None,
     'sync_id': None,
     'user_id': 5050000})