Open oscarclivio opened 2 years ago
@oscarclivio thanks for bringing this up. Sorry for the delayed response, we're full of vacations in December
@PotHix I've tried and moving through setting the project_id
actually works, but it's not in the REST API documentation. I know we have move command on the Sync API, but I'm unsure if there's any extra feature. Can you please let me know if we can support changing the project_id
through the REST API or introduce the move command?
I've tried and moving through setting the project_id actually works
Are you sure? Via task update? That shouldn't work in the current version.
Can you please let me know if we can support changing the project_id through the REST API or introduce the move command?
Yes, that is in the roadmap, preferably without needing a specific endpoint for the move (but needs further exploration). It will certainly get in at some point, we just don't have an ETA yet.
Update: an internal ticket has been created for this, but we can't share a deadline for this. We'll post updates here when we have them.
Any updates on this? Since the SYNC
API v8 will be removed at the end of the month, I won't be able to use the deprecated SYNC
python package.
Sorry for my absence of response, it looks like I forgot I had written this issue.
It looks like the sync API is deactivated now. So any updates on this? It is a key point of my personal task management.
My current workaround (not beautiful, but after a lot of frustrating testing I came to this) for moving a task to a new parent task:
...
req = requests.post('https://api.todoist.com/sync/v9/sync', headers={'Authorization': f"Bearer {TODOIST_APITOKEN}", 'Content-Type': 'application/x-www-form-urlencoded'}, data={'commands': json.dumps([{'type': 'item_move', 'uuid': str(uuid.uuid4()), 'args': {'id': str(previousTask.id), 'parent_id': str(tasks[0].id)}}])})```
if req.status_code != 200:
print(requests.Response.text)
...
the SYNC API v8 will be removed at the end of the month, I won't be able to use the deprecated SYNC python package.
Yes, the Python package is deprecated for a while and will not be updated for v9.
It looks like the sync API is deactivated now.
The Sync API is not deactivated yet. We're going to deprecate the version 8 of the Sync API, but the version 9 is already released and has the same feature.
We know it's a bummer that we still don't have this implemented in the REST API yet, and I hope to be able to prioritize it soon.
Hm, same problem here - v8 depreciated and no python library for v9 ... ... having no possibility to move task - this "basic" method is requesting to be in REST api as I can remember
My current workaround (not beautiful, but after a lot of frustrating testing I came to this) for moving a task to a new parent task:
... req = requests.post('https://api.todoist.com/sync/v9/sync', headers={'Authorization': f"Bearer {TODOIST_APITOKEN}", 'Content-Type': 'application/x-www-form-urlencoded'}, data={'commands': json.dumps([{'type': 'item_move', 'uuid': str(uuid.uuid4()), 'args': {'id': str(previousTask.id), 'parent_id': str(tasks[0].id)}}])})``` if req.status_code != 200: print(requests.Response.text) ...
Hi, I am not pro-programmer - could you help to use your code to move task to another project? Thanks.
@vp-priv
import requests
import uuid
import json
TODOIST_APITOKEN = None # put your token here
task = None # get your task the way you do
project = None # get your project the way you do
req = requests.post('https://api.todoist.com/sync/v9/sync', headers={'Authorization': f"Bearer {TODOIST_APITOKEN}", 'Content-Type': 'application/x-www-form-urlencoded'}, data={'commands': json.dumps([{'type': 'item_move', 'uuid': str(uuid.uuid4()), 'args': {'id': str(task.id), 'project_id': str(project.id)}}])})```
if req.status_code != 200:
print(requests.Response.text)
That should do the trick. Note that this is untested.
A simpler approach:
from uuid import uuid4
TOKEN = "xxx"
def move_task(task_id: str, project_id: str) -> bool:
body = {
"commands": [
{
"type": "item_move",
"args": {"id": task_id, "project_id": project_id},
"uuid": uuid4().hex,
},
],
}
response = requests.post(
"https://api.todoist.com/sync/v9/sync",
headers={"Authorization": f"Bearer {TOKEN}"},
json=body,
)
return response.ok
@ramonvg Thank you very much, I was always lost in requests and uuid, etc - it WORKS. Vladimir
Not the prettiest solution but with the tools available in Todoist REST API (not tested):
from todoist_api_python.api import TodoistAPI
api = TodoistAPI("0123456789abcdef0123456789")
...
def move_task(task, project_id:str=None, section_id:str=None, \
parent_id:str=None, order:int=None):
"""'Moves' a task to a different project/ section or parent by creating a \
identical new one and deleting the old one.
Args:
task (TodoistAPI task object): task-object of the task to move.
project_id (str, optional): Where the task should be moved to. \
Defaults to None.
section_id (str, optional): Where the task should be moved to. \
Defaults to None.
parent_id (str, optional): Where the task should be moved to. \
Defaults to None.
order (int, optional): Where the task should be moved to. \
Defaults to None.
Returns:
task (TodoistAPI task object): If successful. Else returns None.
"""
try:
comments = api.get_comments(task_id=task.id)
except Exception as error:
print(error)
return False
else:
try:
new_task = api.add_task(
content=task.content,
description=task.description,
labels=task.labels,
priority=task.priority,
due=task.due,
assignee_id=task.assignee_id,
project_id=project_id,
section_id=section_id,
parent_id=parent_id,
order=order
)
except Exception as error:
print(error)
return False
else:
for comment in comments:
try:
created_comment = api.add_comment(
content=comment.content,
task_id=task.id,
attachment=comment.attachment
)
except Exception as error:
print(error)
return False
else:
try:
api.delete_task(task_id=task.id)
except Exception as error:
print(error)
return False
else:
return new_task
@Pa7rickStar Hi, thanks - similar to one of my unsuccessful trials one year ago. I just need to move task - any other information I have from Rest API - I cannot use create and delete task because there could be pictures, etc in the comments, and there is no functional possibility to copy them to the new task (did not work one year ago). Vladimir
@jankratochvilcz any update on REST API to move a task between projects? If not, consider this me registering my interest ;)
Well there's 30 min of debugging i'll never get back... turns out that it's not supported, nor is there an error raised/returned to indicate as much :(.
Thanks to @ramonvg for the workaround that ... should not have been needed.
I also need this feature to move a task in another section. Why is this not supported?
Unless I am misunderstanding the basic principle of a REST API, I do not see any function to move a task to another project or section either in the documentation or the code.
Did I miss this method somewhere? Or can this be implemented?