get_workspace_id() fails after using CSV upload
Closed this issue · 1 comments
christophsax commented
I get an error in get_workspace_id()
:
get_workspace_id()
#> Error: Internal error in `vec_assign()`: `value` should have been recycled to fit `x`.
#> Run `rlang::last_error()` to see where the error occurred.
This is because I used the CSV upload in toggle before. If you use it, content(GET(...))
returns a new list elment with two grandchildren, at
and log_id
, which confuses the following bind_rows
.
My return value looks like this (truncated):
content(GET("https://www.toggl.com/api/v8/workspaces",
# verbose(),
authenticate(api_token,"api_token"),
encode="json"))
#> [[1]]
#> [[1]]$id
#> [1] 807353
#>
#> ...
#>
#> [[1]]$ical_enabled
#> [1] TRUE
#>
#> [[1]]$csv_upload
#> [[1]]$csv_upload$at
#> [1] "2020-05-23 10:20:09.505596+00"
#>
#> [[1]]$csv_upload$log_id
#> [1] 4204769
One way to fix it is to use as.data.frame()
instead of bind_rows()
. This seems fine with the grandchildren.
E.g., like this:
get_workspace_id <- function(
api_token = get_toggl_api_token()){
if (is.null(api_token)){
stop("you have to set your api token using set_toggl_api_token('XXXXXXXX')")
}
content(GET("https://www.toggl.com/api/v8/workspaces",
# verbose(),
authenticate(api_token,"api_token"),
encode="json")) %>%
as.data.frame()
.$id -> id
id <- id[1] # si plusieurs workspace , il faudra adapter
if (length(id) == 0){
stop(paste("cant find workspace id - is your api token ok ?"))
id <- NULL
}
id
}
Let me know if you you want me to open a PR.
VincentGuyader commented
Hi thanks
Yes please can you do a PR with the modification you need?
Regards