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

HTTPError when running get_completed_items() #123

Open
programmerPhysicist opened this issue Nov 14, 2023 · 7 comments
Open

HTTPError when running get_completed_items() #123

programmerPhysicist opened this issue Nov 14, 2023 · 7 comments
Labels
question Further information is requested

Comments

@programmerPhysicist
Copy link

programmerPhysicist commented Nov 14, 2023

Question description

I get a HTTPError when I attempt to run get_completed_items() off the api object. I get the following error:
ApiErrorTodoist
is this a bug, or am I doing something wrong?

@programmerPhysicist programmerPhysicist added the question Further information is requested label Nov 14, 2023
@brunorosilva
Copy link

Hi, you seem to be using get_completed_items() without any project nor section filter, which is not supported by this api version (insane, I know). They should give other options to get all completed items, as it was possible before the version update.

Call to endpoint without project_id field

image

Call to endpoint with project_id field

image

There's no direct fix to this, but there's a workaround for non-archived projects. If you know all of the project_ids you can call it with get_all_completed_items(project_id="1231924012").

@lefcha do you guys have any plans to add back the call without the project_id filter? Or maybe give us a way to get archived projects.

@lefcha
Copy link
Collaborator

lefcha commented Nov 17, 2023

Yes, while the public API has a way to get all completed tasks, ie.

https://developer.todoist.com/sync/v9/#get-all-completed-items

Unfortunately we haven't yet implemented very much from the auxiliary functions of the Sync API in this SDK. Your best option for now would be to directly send a request to the https://api.todoist.com/sync/v9/completed/get_all endpoint.

There's also an API endpoint to get archived projects https://api.todoist.com/sync/v9/projects/get_archived, in case you find it useful, documented at:

https://developer.todoist.com/sync/v9/#get-archived-projects

This SDK is primarily about implementing the REST API, and we don't plan to implement all the auxiliary functions of the Sync API at the moment.

@oscarclivio
Copy link

Same problem here.

@brunorosilva
Copy link

@oscarclivio did you try to call the get_completed_items() using a project_id argument?

If you really want to get all of the completed items or you do not know the project_ids you're supposed to use, use the sync api - as lefcha answered me. If you're not sure how to do this, feel free to use this code on my working branch code

@oscarclivio
Copy link

oscarclivio commented Nov 24, 2023

Thanks @brunorosilva for helping. I do yes and I iterate over project ids. But your solution is faster and returns non-root completed tasks unlike get_completed_items() (weird!).

@brunorosilva
Copy link

@oscarclivio Glad I could help!

Yeah, that happens because their implementation of get_completed_items() calls to https://api.todoist.com/sync/v9/archive/items?project_id=<project_id>, and each call takes ~500ms to get 100 completed items (the limit for each call) for a single project as the example below. The endpoint I'm using is https://api.todoist.com/sync/v9/completed/get_all, which takes ~700ms to get 200 completed items (the limit), so this is why it's faster.

Their approach is not wrong, it is in line with their argument for having two APIs. Rest providing simpler use cases and Sync for data heavy use cases.

Below are some images and comparisons I made.
image

Using /archive
See the time below for one project -> 570ms
Screenshot from 2023-11-24 16-23-37
Using /completed
image

@programmerPhysicist
Copy link
Author

programmerPhysicist commented Dec 6, 2023

I came up with the following implementation:

def dict_to_Task(obj, url):
    obj['comment_count'] = obj['note_count']
    obj['is_completed'] = (obj['completed_at'] != '')
    obj['created_at'] = "unknown"
    obj['creator_id'] = obj['user_id']
    obj['description'] = obj['content']
    obj['priority'] = ''
    obj['url'] = url
    return Task.from_dict(obj)

def get_all_completed_items(api):
    url = get_sync_url('completed/get_all')
    completed_items = get(_session, url, _token)
    tasks = completed_items['items']
    return [dict_to_Task(obj, url) for obj in tasks]

This probably could be added to the api, with a few tweaks.

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

4 participants