I’ve been trying for about 3 hours to figure this out, and no amount of trial and error, documentation reading, or forum/internet searching has yeilded an answer. I found a few posts here with people asking similar questions, but either the solution isn’t helping me or nobody ever answered the question.
Here’s what I want to do. I want to use the Rest API to run a script, but I want to pass some data to the script from the external call. Here’s what I have for a CURL command (for testing):
curl \
-H "Content-Type: application/json" \
-H "Authorization: Bearer MYTOKEN" \
-d '{"entity_id": "script.launch_streaming_video","the_url": "https://www.disneyplus.com/video/afdc98f1-26bf-48d8-8866-af185ba5d5ac"}' \
http://MY_IP/api/services/script/turn_on
And the script:
alias: Launch Streaming Video
fields:
the_url:
description: The URL to the episode or movie
example: https://www.disneyplus.com/video/afdc98f1-26bf-48d8-8866-af185ba5d5ac
sequence:
- service: media_player.play_media
data:
media_content_type: url
media_content_id: "{{ the_url }}"
target:
device_id: 6c498452766127570b04aefeffcee4a9
mode: single
icon: mdi:television
The script works fine if I call it from the HA developer tools and pass a URL. If I try it from CURL I get a 400: Bad Request response. If I remove the second item from the JSON (i.e. the_url), it “works” but with no data passed to the script.
Is there a way to call a script and pass it some data?