SyncError http 400
hbernhard opened this issue · comments
I am just starting to use this library and am getting a consistent error when trying to remotely delete or move items with ItemsManager. I can successfully close items, but when I try move, delete, complete or update I get an http 400 error. I don't know if I am using the commit function incorrectly (though it works for the "close" item) so I have attached a sample script that throws the error for review. I am running python 2.7
`import todoist
#enter your username and password
username = 'user@gmail.com'
pw = 'password'
api = todoist.TodoistAPI()
pm = todoist.managers.projects.ProjectsManager(api)
im = todoist.managers.items.ItemsManager(api)
user = api.user.login(username, pw)
response = api.sync()
#This will sucessfully add an item to the inbox immediately without committing
api.add_item('Item sent from Python One')
api.add_item('Item sent from Python Two')
projects = response['projects']
#inbox
inbox = projects[0]
inboxID = inbox['id']
#get first item
data = pm.get_data(inboxID)
items = data['items']
first_itemID = items[0]['id']
first_itemString = items[0]['content']
#this works and marks the item as complete
im.close(first_itemID)
api.commit()
print('"{}" sucessfully marked as completed'.format(first_itemString))
#get next item
data2 = pm.get_data(inboxID)
items2 = data2['items']
sec_itemID = items2[0]['id']
sec_itemString = items2[0]['content']
#this does not work nor do any command to update item remotely (move, delete, complete, update)
im.delete(sec_itemID)
print('attempting to delete "{}"'.format(sec_itemString))
api.commit()
`
Running your code, I see the following error message:
todoist.api.SyncError: ('993f5a11-1d10-11e8-93ef-d07e35dc68ec', {'error_extra': {'expected': 'list', 'argument': 'ids'}, 'error_tag': 'INVALID_ARGUMENT_VALUE', 'error': 'Invalid argument value', 'command_type': 'item_delete', 'error_code': 20, 'http_code': 400})
It tells you two things:
- An invalid argument value was passed ( 'error': 'Invalid argument value')
- It was expecting a list, not a single value ('expected': 'list')
For the purposes of your example code, you can simply surround your single item in brackets to insert it into a list.
im.delete([sec_itemID])
In practice, you'd want to abstract that out properly into a variable, particularly if you wanted to delete multiple items at the same time.
I suspect that you expected im.close() and im.delete() to behave the same way. They do not appear to do so as close() takes only a single item.
I would also suggest moving away from using user name and password and using the API Token provided by Todoist. It can be found in Settings -> Integrations.
Your code would then read like:
api = todoist.TodoistAPI(token='8932471234384327489237492347631283748267')
pm = todoist.managers.projects.ProjectsManager(api)
im = todoist.managers.items.ItemsManager(api)
response = api.sync()
This gives you greater flexibility if in the future you wrote your code as a true third party integration usable by other Todoist customers.
Lastly, I forgot to mention that there is one other error in your code:
projects = response['projects']
... should be ...
projects = api.state['projects']
It was a great response by @seliger (thanks for that!), I'm closing this issue.
@hbernhard please reopen if you still need anything from us.