Todoist API Actions - Any help with tweaks appreciated

Todoist API Actions - Any help with tweaks appreciated

I have a series of actions that I’ve used with the Todoist API over the years. But, to be quite honest, none of them really work how I’d like them to.

If anyone out there could help with tweaks to the code in each instance to make them fit the bill as outlined below, I would really appreciate any input you can provide. Cheers.

1. Import a project’s tasks, but also include Sections if they exist

Original script/action

This action works fine in that it pulls in the tasks and due dates for any project selected from the prompt when the action is run. However, just over a year ago, Todoist introduced a new entity, Sections, within projects.

So it would be great if, upon import, if any Sections exist, they are listed and preceded by using 3 hashtags (project title is preceded by 2 hashtags), with the tasks relating to each Section then listed below it. In essence, work as it currently does, but just insert the title of Sections where appropriate in the list of project tasks.

2. Import a project’s comments - Timestamped & clear delineation between comments

Original script/action

Again, the original script works fine to a degree. However, it would be great if it would also include:

  • The timestamp of comment creation, just as it appears on Todoist
  • An identifiable break between each comment (i.e., Markdown triple asterisk/dash)

Comments to flow oldest to newest as per original.

3. Add a comment to project’s comments from a selectable list of existing project names

Original script/action

I currently have an action that can send comments to a specified project whose ID is ‘hard-coded’ into the script. It would be great if I could instead select the project from a prompt list and then add the comment (draft content) to it.

This action by another contributor on the action directory does a similar thing, but you first select a project, then a task to add a comment to the task. Incidentally, this action works OK in that it adds the comment to a Todoist task when executed, but Drafts warns it’s failed “undefined.”

to 1):
currently it is not possible to retrieve the sections with drafts own implementation of the todoist API: https://scripting.getdrafts.com/classes/todoist
there is no “getSections” method implemented - this is something @agiletortoise would have to implement.
Of course the section ID could be read from the tasks and mapped back to the section names and so on, but this seems kind of hacky to me…

to 2):
I modified the action, maybe this fits your needs: https://actions.getdrafts.com/a/1fJ

to 3):
Again, I modified the action, hopefully this fits your needs: https://actions.getdrafts.com/a/1fK

If you have any issues just reply :slight_smile:

EDIT:

thanks to the reply from agiletortoise, I created an action to hopefully help you with the section import from 1): https://actions.getdrafts.com/a/1fM
Hope this looks how you wanted. The last subsection will always be „NO SECTION“ and hold all tasks which are not in a section.

There may be issues when running this on different projects, it is not fully tested. Please report any issues with it

1 Like

Sections did not exist when I created the convenience methods on the Todoist API, but note that you can call any method in the Todoist REST API using the request function on the Todoist object - so you could call their sections APIs directly if desired.

I’ll make a note about adding convenience methods for sections, but it’s not that much more difficult to make the requests directly.

I’ll take a look, thanks for pointing that out.

convenience functions to the sections would be great anyways :slight_smile:

First, many thanks for taking the time out to help on this. I really appreciate it.

Both 1 and 3 are fantastic. Great work incorporating the Sections there so quickly. Brilliant.

2 is also great but there are just a few things I would prefer and as is usually the case, should have clearly specified at the outset.

  • The Markdown header to include the project name, not just “Comments”
  • I was after the date being on its own on the first line and then with a line break between it and the comment. Thinking about it a bit further, and continuing the Markdown theme, it would be great if the date was preceded by 4 hashtags
  • The date not to be in brackets
  • The date format to follow just as in Todoist’s comments , so 8 Dec 3:03 PM for example
  • No triple dash after the last comment that is imported

Even without those points it’s still marvellous, so thanks again for your help.

please see an update for 2) here: Todoist: Import Project Comments with Date | Drafts Directory

I don’t know what you mean. The project name is used as the header (markdown header level two). If you want to have something different included in the header, simply edit line 64 in the sciript.

I implemented this, there won’t be a delimiter after the last comment, anyways since the Dates are now a header, I think the comments are clearly separated by that header level. You can therefore disable the delimiter completely if you switch the variable in line 8 to ‘false’.

1 Like

Wonderful. Apologies. Earlier today, I imported comments from a project that contained a lot of Markdown in it. Consequently, it was difficult to easily assess the layout made by the import. So, I set up a new project to add some comments to, and in my infinite wisdom/stupidity, called it “Comments.” So I got a bit mixed up thinking the action was writing "Comments.":relieved:

You’ve done a lovely job here. Thanks ever so much for your help. These will be so handy.:+1:

1 Like

Can you just explain what you are doing with the imports of the comments or the „complete project export“ with the sections?
Would be interesting to here what your usecase is :slight_smile:

Glad I could help you - and as ever learned something new about drafts and JavaScript :+1:t3:

1 Like

Primary use case is, sharing information from Todoist with non-Todoist users is not a great experience. Print to PDF etc. Yes, ideally, they’d be on a shared project, but there might be a myriad reasons for this not happening.

So, by pulling down the information from Todoist in plain text/Markdown, it can be easily shared via email. Further, it means the Todoist Project can continue to be the central hub for notes etc. (i.e., comments), retaining the convenience of timestamps, safe in the knowledge that it can be easily shared with non-Todoist users if need be. Hope that makes sense.

1 Like

sounds reasonable, thanks!

FYI, added sections-related convenience methods to the Todoist object in the latest beta, if you are interested in testing them. Should be out in release soon.

I saw the release notes in TestFlight but didn’t have time to test them unfortunately - thanks anyways for the great addition!