1

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
jason
  • 3,471
  • 6
  • 30
  • 43
  • 1
    That's a UUID. Why do you say it's not usable? – jonrsharpe Jul 30 '19 at 07:12
  • When I use that ID in a api.items.get_by_id() call, the response says this is an unknown ID. I have some regular items with integer IDs and they work just fine with the get_by_id call. – jason Jul 30 '19 at 07:37

1 Answers1

1

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})
PotHix
  • 91
  • 3
  • Got it, Sometimes the temp ids linger a while. Even after several commits. But eventually, they disappear. This is weird, and I am handling this using an exception right now. Just keep committing till they disappear. – jason Aug 08 '19 at 04:53
  • 1
    Hm, that shouldn't happen. If you can make some code to reproduce it, please add an issue in the official repository with the code so we can work on a fix: https://github.com/Doist/todoist-python/issues – PotHix Aug 08 '19 at 10:30