Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't move a task to another project/section? #8

Open
oscarclivio opened this issue Dec 22, 2021 · 17 comments
Open

Can't move a task to another project/section? #8

oscarclivio opened this issue Dec 22, 2021 · 17 comments
Assignees
Labels
question Further information is requested

Comments

@oscarclivio
Copy link

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?

@jankratochvilcz jankratochvilcz added the question Further information is requested label Dec 27, 2021
@jankratochvilcz
Copy link
Contributor

@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?

@PotHix
Copy link
Member

PotHix commented Dec 31, 2021

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.

@jankratochvilcz
Copy link
Contributor

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.

@ghost
Copy link

ghost commented Oct 16, 2022

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.

@oscarclivio
Copy link
Author

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.

@ghost
Copy link

ghost commented Oct 17, 2022

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)
...

@PotHix
Copy link
Member

PotHix commented Oct 17, 2022

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.

@vp-priv
Copy link

vp-priv commented Dec 8, 2022

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

@vp-priv
Copy link

vp-priv commented Dec 8, 2022

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.

@ghost
Copy link

ghost commented Dec 8, 2022

@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.

@ramonvg
Copy link

ramonvg commented Dec 9, 2022

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

@vp-priv
Copy link

vp-priv commented Dec 12, 2022

@ramonvg
Thank you very much, I was always lost in requests and uuid, etc - it WORKS.
Vladimir

@Pa7rickStar
Copy link

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

@vp-priv
Copy link

vp-priv commented Dec 12, 2022

@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

@nstielau
Copy link

nstielau commented Mar 1, 2023

@jankratochvilcz any update on REST API to move a task between projects? If not, consider this me registering my interest ;)

@kquinsland
Copy link

kquinsland commented May 18, 2023

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.

@miba87
Copy link

miba87 commented Jan 28, 2024

I also need this feature to move a task in another section. Why is this not supported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

9 participants