How to "translate" an action YAML to a REST API call?

I’m trying to call an action through REST API, but can’t find the way to translate some actions to service calls. If I want to send a notification to my mobile phone, from the developer tools I can call the action with the following YAML:

action: notify.mobile_app_phone_name
data:
  message: Lorem ipsum
  title: Lorem ipsum

I can send a POST request to http://hassio-url:8123/api/services/notify/mobile_app_phone_name and the data array sent as form fields and works OK.

But if I want to create an event on Google, I can run the following action on the developer tools:

action: google.create_event
data:
  summary: Lorem ipsum
  description: 2024-12-03 10:00
  start_date_time: 2024-12-03 12:00
target:
  entity_id: calendar.personal

If the action goes on the URL an the data is sent as POST fields, how do I send the target?.

Thanks!

Did you try just adding entity_id to the payload?

Yes, resulting in a 400: Bad Request response.

According to REST API / Service Calls / Specify Target - #2 by ElVit, that should work.

Please post your curl command

Sorry! You were right: specifying entity_id works!

As all returned errors are 400: bad request could not differentiate the source of the error. I was calling the action google.add_event instead of google.create_event and that’s why it failed.

So, for the following YAML:

action: google.create_event
data:
  summary: Lorem ipsum
  description: 2024-12-03 10:00
  start_date_time: 2024-12-03 12:00
target:
  entity_id: calendar.personal

The equivalent REST API call will be:

curl --location 'http://hassio-url:8123/api/services/google/create_event' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
    "entity_id": "calendar.personal", 
    "summary": "Lorem ipsum", 
    "start_date_time": "2024-12-03 10:00", 
    "end_date_time": "2024-12-03 10:00" 
}'

I hope this will help others…

2 Likes