Updating a specific service using REST POST API takes more than 20 seconds to executes

Is it normal that updating a service status using REST API call from client machine takes around 22 seconds?

I’m using Home Assistant Core version: core-2021.10.2 using Home Assistant OS Release-6 build 6 on raspberryPi

This behavior/delay happens only whenever I’m calling the REST API from a client machine using curl command as follows:

curl -X POST -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxMDQyMWQ4NTA4ZDQ0OWJlOThkZmI1MzNmMWFlNTkzYiIsImlhdCI6MTYzNTc5OTkzMiwiZXhwIjoxOTUxMTU5OTMyfQ.6_e_5_q2X_PLgJtLC4vRPZrLfNDxW3tC3Sej4wGB624" -H "Content-Type: application/json" -d '{"entity_id": "switch.leaving_room_2nd_3rd_2**"}' http://homeassistant.local:8123/api/services/switch/turn_off

however if I tried to use homeassistant dashboard UI or even the Developer Tools >> Services call it switch off or on instantly without any delay.

Is it because of the Authorization token or something else? and how could I fix this issue?

Try the Rest Command integration.

To avoid confusion, the OP is using the HA API, not trying to reach an external device via REST :wink:

1 Like

Thanks a lot for your quick response.

I’m newbie so maybe I’m asking nonsense or basic questions:

  1. how this RESTFUL command different from RESTFUL APIs REST API | Home Assistant Developer Docs

  2. How to call this RESTFUL command from independent tool maybe something like curl or any other tool as my goal is to add this call in a program
    and not just add it to an automation or a script that is called/managed by home Assistant.

  3. when should and shouldn’t use the REST API | Home Assistant Developer Docs
    as a mean to query or to update entities or services

Ignore my post. As Chris pointed out I misunderstood your question.