Cast-web-api and WebCoRE JSON issue

I’m creating a new WebCoRE task for the cast-web-api. I can confirm everything is working as expected using curl in terminal. Audio notifications using googleTTS work immediately.

I’m using a playMedia call for my URL value: http://1.1.1.2:3001/device/abc123/playMedia

I have no response when submitting data this way. Instead, I have to use CUSTOM for the Request Body Type and then paste in raw JSON to at least have it ‘ding’ on my Google Home. This provides an error about a ternary operator since curly braces are interpreted as variables. Escaping the braces doesn’t help. Nothing plays.

It seems so simple,. I can get this to work with a REST client. I’m honestly unsure what I should be doing to get this to work as expected in WebCoRE. Anyone have some options to try?

Finally got it to work! Here’s my code for notifications using cast-web-api:

The kicker is setting the data variable using escape characters and injecting the command variable to customize it. This allows for dynamic notifications:
{’[{“mediaTitle”:“Door opened”, “googleTTS”:“en-UK”}]’}
To insert the variable mid line, '} {variable} {' is used. Single quotes are used to encapsulate the string. Result of inserting the command variable:
{’[{“mediaTitle”:"’}{command}{’", “googleTTS”:“en-UK”}]’}

I hope this saves someone 2 days of pain… (it’s the only reason I registered an account on here).

2 Likes

Check that