Curl template Area_devices returns an empty list

Hi,

Using curl I can get a list of rooms :


curl -H 'Authorization: Bearer myBearer' '192.168.1.19:8123/api/template' -d '{"template": "{{ areas() }}"}'

['living_room', 'kitchen', 'bedroom']

but when I want to get the devices attached to a room, I get an empty list

curl -H 'Authorization: Bearer myBearer' '192.168.1.19:8123/api/template' -d '{"template": "{{ area_devices('kitchen') }}"}'             
 
[]%

Can someone please help me with this ?

Works for me.

Doe the “Kitchen” area page from settings actually show devices?

Yes :frowning: , I tried a few rooms to be sure. The issue happens for all of them.

I guess you tried the template in the template debugger and it also returns an empty list, right?
Could you show an actual screenshot of your kitchen area in HA, please.

The template in the template debugger works, but I’ll need to use the API

Fair enough, but if it works in the debugger, it must work through api as well. It’s exactly the same call, just made through the api rather than the UI.

The only reason I can see is that you are not actually talking to the proper HA. Do you have multiple instances?

I have one instance but it’s all good, it actually works in PostMan. I’m still curious why it wouldn’t work with curl but at least I’m not blocked anymore.

Thanks for your help :slight_smile:

escape your quotes inside the template.

The command is only seeing from the first single quote to the 2nd single quote.

1 Like

Of course it was that ! I knew it was a stupid mistake. Cheers !

For anyone looking to curl that :


curl -H 'Authorization: Bearer myBearer ' '192.168.1.19:8123/api/template' -d '{"template": "{{ area_devices('\''kitchen'\'') }}"}'