API for Todo lists

Hi there,

Is it possible to get Todo list items from the rest API?
I’ve tried using the services endpoint, however, I receive a 500 error - request is below…

curl --location 'http://homeassistant.local:8123/api/services/todo/get_items' \
--header 'Authorization: Bearer <TOKEN> \
--header 'Content-Type: application/json' \
--data '{
    "entity_id": "todo.test"
}'

Thanks!

1 Like

Same issue here. I’d love to hook up my Habitica dailies to a To Do list that cycles daily so I can do it all from my HASS dashboard, but getting the current list is proving to be a challenge.

Still having the issue with 2024.3.0…

Would love to get the list items to build a mobile app, to put fridge groceries (and their due date) and finally retrieve the items. But for now, I am only able to create new items

someone resolved by chance?
Same problem here with 2024.04!

Logger: aiohttp.server
Source: /usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py:421
First occurred: 10:15:43 PM (1 occurrences)
Last logged: 10:15:43 PM
Error handling request

Traceback (most recent call last):
File “/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py”, line 452, in _handle_request
resp = await request_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py”, line 543, in _handle
resp = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py”, line 114, in impl
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/security_filter.py”, line 92, in security_filter_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/forwarded.py”, line 210, in forwarded_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/request_context.py”, line 26, in request_context_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/ban.py”, line 88, in ban_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/auth.py”, line 236, in auth_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/http/headers.py”, line 32, in headers_middleware
response = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/helpers/http.py”, line 73, in handle
result = await handler(request, **request.match_info)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/api/init.py”, line 406, in post
await shield(
File “/usr/src/homeassistant/homeassistant/core.py”, line 2498, in async_call
raise ValueError(
ValueError: Service call requires responses but caller did not ask for responses

for everyone who will ask for answers :smiley:

I finally managed to get what I needed using websocket (GitHub - websocket-client/websocket-client: WebSocket client for Python).
Here’s a simple python script to obtain items!
(that now I have to translate since my custom backend is in php :sweat_smile:).

from websocket import create_connection
import json
 
 ws = create_connection("ws://homeassistant.local:8123/api/websocket")
 
 token = LONG_LIVED_TOKEN 
 message = {
   "type": "auth",
   "access_token": token
 }
 
 ws.send(json.dumps(message))
 result =  ws.recv()
 result =  ws.recv()
 message = {
   "type": "call_service",
   "domain": "todo",
   "service": "get_items",
   "target": { "entity_id": "todo.shopping_list" },
   "id": 1,
   "return_response": True
 }
 ws.send(json.dumps(message))
 result =  json.loads(ws.recv())
 #print("'%s'" % result)
 print("'%s'" % result["result"]["response"]["todo.shopping_list"]["items"])
 
 ws.close()

result:

 '[{'summary': 'item1', 'uid': '0385d94151bc248591f6d5d47bc77ca4', 'status': 'needs_action'}, {'summary': 'item2', 'uid': 'c2058040fd6c49csa418431sd8f7985e', 'status': 'needs_action'}]'

Cheers!

and here the equivalent php script
(GitHub - gabrielbull/php-websocket-client: A simple WebSocket WAMP client implemented in PHP)

<?php

namespace WebSocket;
require 'vendor/autoload.php';

$client = new Client('ws://192.168.1.5:8123/api/websocket');
$message =  $client->receive();
$token = LONG_LIVED_TOKEN
$client->text(json_encode(array('type' => 'auth', 'access_token' => $token)));
$message = $client->receive();

$message = array (
  'type' => 'call_service',
  'domain' => 'todo',
  'service' => 'get_items',
  'target' => array ( 'entity_id' => 'todo.shopping_list' ),
  'id' => 1,
  'return_response' => True
);

$client->text(json_encode($message));
$message = $client->receive();
echo "Got message: {$message->getContent()} \n";

$client->close();
?>