Web Request POST to internal server - JSON problems


#1

1) Give a description of the problem
Trying to create a simple piston that calls a REST API POST method with JSON body.
The destination is a local IP address in my network for a Sony AV receiver. (API reference guide if needed: https://developer.sony.com/develop/audio-control-api/hardware-overview/api-references/svs/getplayingcontentinfo)
But the JSON appears to be getting modified somehow. Is there a way to log the Web Request to see exactly what it’s sending?

2) What is the expected behavior?
When I call the API with Postman, it returns a JSON object.

3) What is happening/not happening?
Something is happening to the POST’s JSON body within WebCoRE. The Sony receiver is returning “error”: [5,“Illegal JSON”]
I can reproduce this error message in Postman if I mess with the the body (like removing quotes around a parameter). So I’m pretty sure I’m not escaping characters properly here somewhere within my WebCoRE code. I also can’t figure out all the “Invalid ternary operator” errors no matter how many times I read the wiki post on it.

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
( 9:00:16 PM: trace ║╚ Execution stage started
9:00:16 PM: debug ║ RunTime Analysis CS > 89ms > PS > 102ms > PE > 94ms > CE
9:00:16 PM: trace ║╔ Execution stage complete. (5ms)
9:00:16 PM: debug ║ Calculating (string) version : (decimal) 1.2 >> (string)
9:00:16 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
9:00:16 PM: debug ║ Calculating (string) , (string) version >> (string) version
9:00:16 PM: debug ║ Calculating (string) params : (string) >> (string)
9:00:16 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
9:00:16 PM: debug ║ Calculating (string) , (string) params >> (string) params
9:00:16 PM: debug ║ Calculating (string) id : (integer) 1 >> (string)
9:00:16 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
9:00:16 PM: debug ║ Calculating (string) , (string) id >> (string) id
9:00:16 PM: debug ║ Calculating (string) method : (string) getPlayingContentInfo >> (string)
9:00:16 PM: debug ║ Calculating (string) output : (string) extOutput:zone?zone=1 >> (string)
9:00:16 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
9:00:16 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
9:00:16 PM: info ╚ Received event [hub].time = 1523246417388 with a delay of -1115ms
8:59:57 PM: info ║║ {“error”:[5,“Illegal JSON”]}
8:59:57 PM: debug ║ Calculating (string) version : (decimal) 1.2 >> (string)
8:59:57 PM: trace ║ Runtime (39943 bytes) successfully initialized in 52ms (v0.3.104.20180323) (144ms)
8:59:57 PM: debug ║ RunTime Analysis CS > 16ms > PS > 52ms > PE > 75ms > CE
8:59:57 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
8:59:57 PM: debug ║ Calculating (string) , (string) version >> (string) version
8:59:57 PM: debug ║ Calculating (string) , (string) params >> (string) params
8:59:57 PM: debug ║ Calculating (string) id : (integer) 1 >> (string)
8:59:57 PM: debug ║ Calculating (string) params : (string) >> (string)
8:59:57 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
8:59:57 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
8:59:57 PM: debug ║ Calculating (string) , (string) id >> (string) id
8:59:57 PM: debug ║ Calculating (string) method : (string) getPlayingContentInfo >> (string)
8:59:57 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
8:59:57 PM: debug ║ Calculating (string) output : (string) extOutput:zone?zone=1 >> (string)
8:59:57 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
8:59:57 PM: info ╚ Received event [Hermosa].wc_async_reply = httpRequest with a delay of 0ms
8:59:57 PM: debug ║║ Sending internal web request to: local.ip.add.ress:10000/sony/system
8:59:57 PM: debug ║║ Cancelling statement #1’s schedules…
8:59:57 PM: info ║ Setting up scheduled job for Sun, Apr 8 2018 @ 9:00:17 PM PDT (in 19.973s)
8:59:57 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
8:59:57 PM: trace ║╚ Execution stage started
8:59:57 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
8:59:57 PM: debug ║ Calculating (string) id : (integer) 1 >> (string)
8:59:57 PM: debug ║ Calculating (string) , (string) params >> (string) params
8:59:57 PM: debug ║ Calculating (string) , (string) id >> (string) id
8:59:57 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
8:59:57 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
8:59:57 PM: debug ║ Calculating (string) method : (string) getPlayingContentInfo >> (string)
8:59:57 PM: error ║ Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
8:59:57 PM: debug ║ Calculating (string) output : (string) extOutput:zone?zone=1 >> (string)
8:59:57 PM: info ╚ Received event [hub].test = 1523246397080 with a delay of 3ms
)


Need your feedback on a new key-value piston input type in webCoRE
#2

I think you are out of luck. Simple JSON strings (several field:value pairs) can work just fine, but you’ll never get nested values (your params field). You have to use multiple variables, and include all in the data. You can’t get Webcore to send a literal variable string already formatted as JSON.

milhouse


“Backup Bin Updated” msg while trying to save Piston - Does not save to cloud