Guys, I have to realize I need help!
I’m trying to update a filter view in Todoist via API. It’s working fine via curl but for my life I cant get it to work with Home Assistant… I’ve been tinkering around for hours and before I go crazy, I really hope you can help!
So to update the filter view I can use Todoist’s sync API.
https://developer.todoist.com/sync/v9/
Using curl under Windows, I can successfully update the filter view with this command
Note: Private info redacted with xxx, UUID needs to be unique per call
C:\Users\User>curl "https://api.todoist.com/sync/v9/sync" -H "Authorization: Bearer xxx)" -d commands="[{""type"": ""filter_update"", ""uuid"": ""veryunique-test-1668344060.5519162"", ""args"": {""id"": ""xxx"", ""name"": ""Working On Context"", ""query"": ""no date"" } } ]" -v
* Trying 13.224.189.69:443...
* Connected to api.todoist.com (13.224.189.69) port 443 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
> POST /sync/v9/sync HTTP/1.1
> Host: api.todoist.com
> User-Agent: curl/7.83.1
> Accept: */*
> Authorization: Bearer xxx
> Content-Length: 171
> Content-Type: application/x-www-form-urlencoded
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 223
< Connection: keep-alive
< Date: Sun, 13 Nov 2022 14:02:59 GMT
< Cache-Control: no-cache
< Referrer-Policy: strict-origin-when-cross-origin
< Set-Cookie: csrf=e0d0ce38577240e29d64c82ace111c50; Expires=Wed, 10-Nov-2032 14:02:58 GMT; Secure; Path=/; SameSite=None
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
< Vary: Accept-Encoding
< X-Cache: Miss from cloudfront
< Via: 1.1 2bbba694ff55d664208103e9c25dce14.cloudfront.net (CloudFront)
< X-Amz-Cf-Pop: FRA2-C1
< X-Amz-Cf-Id: yK98I66W_eJo-5C5Rj23CTli-I2HkD9oe6rlHZm94EK-yqk-MBCK9g=
{"full_sync":true,"sync_status":{"veryunique-test-1668344060.5519162":"ok"},"sync_token":"xxx","temp_id_mapping":{}}* Connection #0 to host api.todoist.com left intact
So far so good…
Now I want Home Assistant to be able to issue the command, so I setup a rest_command in the config:
todoist_sync_endpoint:
url: https://api.todoist.com/sync/v9/sync
method: POST
headers:
authorization: !secret todoist_token
payload: '{{ "commands=" + payload }}'
content_type: 'application/x-www-form-urlencoded'
verify_ssl: true
payload is then being set via service call but I was never able to get it to work. I suppose there is a problem with the inverted commas and it fells like I basically tried every possible solution.
So questions are, (1) did I setup the rest_command correctly for the call I’m trying to make and (2) how do I have to hand over the POST data to make it work?
A basic example for a curl request from the API documentation would look like this:
$ curl https://api.todoist.com/sync/v9/sync \
-H "Authorization: Bearer 0123456789abcdef0123456789abcdef01234567" \
-d commands='[
{
"type": "filter_update",
"uuid": "a68b588a-44f7-434c-b3c5-a699949f755c",
"args": {
"id": "4638879",
"name": "Not Important"
"query": "priority 4"
}
}]'
So as the “commands=” part is in the payload already, the rest should look something like this (including the inverted comma at beginning and end):
'[{"type": "filter_update", "uuid": "veryunique-test-1668344060.916", "args": {"id": "xxx", "name": "Working On Context ", "query": "no date" } }]'
Really hope someone can help. It can’t be that hard, right?!