Web request with json body


#1

Hi there,

Im sure its something negligible but for the love of god i cant seem to see what is the problem

Theres is no errors whatsover in my logs

Basically im calling a service on home assistant, im confident theres no issue with the http, i tested my link on postman by sending a http post with the body and it works

https://xxxxx.duckdns.org:8123/api/services/tts/amazon_polly_say?api_password=xxxx
body: {“entity_id”: “media_player.living_room_speaker_2”,“message”:“Turning off TV”}

Am i doing it correctly on webcore?
I also know that it is reaching my home assistant however im getting this:

Invalid service data for tts.amazon_polly_say: extra keys not allowed @ data[‘data’]. Got {‘entity_id’: ‘media_player.living_room_speaker_2’, ‘message’: ‘Turning off TV’}
required key not provided @ data[‘message’]. Got None

Any thoughts on this?


#2

Define the ‘entity_id’ and ‘message’ variables separately, set your values and, in the POST request, send those variables instead of ‘data’. webCore will format the json automatically.


Json post parameters
Sending data in a POST
#3

Thanks, this works!


#4

This example was most helpful, thank you!

I wonder if its possible to use the same piston to define multiple possible strings…
Using your example I’d like to use the same piston (rather than writing one for each device) and specify which device media_player.living_room_speaker_2 or bedroom_speaker etc

The problem when the web request gets sent it uses the string name as the handler and then the variable.

My specific example is I have a huge piston full of if statements checking the time of day, a forecast of the weather and then sends a query to my tesla power wall to either charge it from the grid, or self consume the battery for the house.

I have a few constants I send such as username & password, these values don’t change, however depending on what I want the power wall to do, i either need to send mode = backup or mode = self_consume


#5

You can do a set variable at the beginning of the condition just like my example above?


#7

I am having a similar problem with the variable string name being sent. What was your solution?


#8

I’ve signed up for the Amazon Polly service and successfully generated some TTS mp3 files.

I’m trying to figure out if your piston would allow me to send a string of text to the Polly service, then have it play on my Sonos speakers?

Any insight?