0

I am not very good with working with API's "From scratch" so to speak. My issue here is probably more to do with my ignorance of RESTful API's than the Todoist API specifically, but I'm struggling with Todoist because all of their documentation is geared around python and I'm not sure why my feeble attempts are failing. Once I get connected/authenticated I think I'll be fine.

Todoist documentation

I've tried a couple of configurations using httr::GET(). I would appreciate a little push here as I get started.

Things I've tried, where key is my api token:

library(httr)
r<-GET("https://beta.todoist.com/API/v8/", add_headers(hdr))

for hdr, I've used a variety of things:

  • hdr<-paste0("Authorization: Bearer", key)
  • just my key

I also tried with projects at the end of the url

Chris Umphlett
  • 380
  • 3
  • 15
  • Please show us your ("feeble"?) attempts; it helps to fix your code (in your style or adjusting your style) than generate full-code from scratch. Also, I believe that Todoist requires an account, so some or many of us will not be able to actually test code, so it'll help to provide a semblance of the responses you get from them that are good-enough for one step but you can't work with for the next. Etc. – r2evans Mar 31 '19 at 20:42
  • added detail. not sure it will be very helpful, and it's not much. i've also tried using a package someone developed which starts with a login (username/pwd) authentication and that didn't work either. the documentation at the repo is not up to date. (devtools::install_github("karthikram/rtodoist") ) – Chris Umphlett Mar 31 '19 at 20:49

1 Answers1

0

UPDATE These are now implemented in the R package rtodoist.


I think you nearly had it except the url? (or maybe it changed since then) and the header. The following works for me, replacing my_todoist_token with API token found here.

library(jsonlite)
library(httr)
projects_api_url <- "https://api.todoist.com/rest/v1/projects"

# to get the project as a data frame
header <- add_headers(Authorization = paste("Bearer ", my_todoist_token))
project_df <- GET(url = projects_api_url, header) %>%
  content("text", encoding = "UTF-8") %>%
  fromJSON(flatten = TRUE)

# to create a new project
# unfortunately no way to change the dot color associated with project
header2 <- add_headers(
  Authorization  = paste("Bearer ", my_todoist_token),
  `Content-Type` = "application/json",
  `X-Request-Id` = uuid::UUIDgenerate())

POST(url = projects_api_url, header2,
     body = list(name = "Your New Project Name"
                 # parent = parentID
                 ),
     encode = "json")

# get a project given project id
GET(url = paste0(projects_api_url, "/", project_df$id[10]),
    header) %>%
  content("text", encoding = "UTF-8") %>%
  fromJSON(flatten = TRUE)

# update a project 
POST(url = paste0(projects_api_url, "/", project_df$id[10]),
    header2, body = list(name = "IBS-AR Biometric 2019"), encode = "json") 
Emi
  • 3,514
  • 8
  • 11
  • 1
    thank you! I'm able to get my projects, this should allow me to get at other pieces as well. much appreciated. – Chris Umphlett Aug 03 '19 at 00:37
  • @ChrisUmphlett Documentation is still lacking but I have most of the project/task actions implemented in https://github.com/karthik/rtodoist – Emi Aug 04 '19 at 11:42
  • Yup I suggested to Karthik I'll update it. A bit more documentation added (along with some breaking API changes) – Emi Aug 05 '19 at 01:21
  • @ChrisUmphlett if you would like to contribute, I'll be happy for you to do so as I think Karthik – Emi Aug 05 '19 at 01:22