- Posts: 32
- Thank you received: 2
Run Curl command in a macro
- randyf
- Topic Author
- Offline
- User
-
Less
More
2 years 4 months ago #1552
by randyf
Run Curl command in a macro was created by randyf
Is there a way to setup a macro to call a curl command and parse the output of the command?
Thanks
Thanks
Please Log in to join the conversation.
- davep
- Offline
- Admin
-
Less
More
- Posts: 367
- Thank you received: 96
2 years 4 months ago #1563
by davep
Replied by davep on topic Run Curl command in a macro
You can use the myServer run command to execute the curl command but it will discard the response. I can modify that to capture the response but problem is how to make a meaningful parser for the response? Can you provide an example of what you'd be looking to parse?
Please Log in to join the conversation.
- randyf
- Topic Author
- Offline
- User
-
Less
More
- Posts: 32
- Thank you received: 2
2 years 4 months ago #1571
by randyf
Replied by randyf on topic Run Curl command in a macro
I'm trying to run this command to get the input list for the TV:
curl -k -H "Content-Type: application/json" -H "AUTH: Z123456790" -X GET https://192.168.1.100:7345/menu_native/dynamic/tv_settings/devices/current_input
This will return a JSON string with some info:
{"STATUS":{"RESULT":"SUCCESS","DETAIL":"Success"},"URI":"/menu_native/dynamic/tv_settings/devices/current_input","PARAMETERS":{"HASHONLY":"FALSE","FLAT":"TRUE","HELPTEXT":"FALSE"},"ITEMS":[{"CNAME":"current_input","TYPE":"T_STRING_V1","NAME":"Current Input","VALUE":"HDMI-1","ENABLED":"FALSE","HIDDEN":"TRUE","HASHVAL":2129379411}],"HASHLIST":[222710829,1702838742]}
If this can be returned as a string, that might work. In myServer5, there were some string functions that could be use to parse the string. For this particular instance, I'm looking for the data from HASHVAL so that I can use it on a subsequent call.
Thanks
curl -k -H "Content-Type: application/json" -H "AUTH: Z123456790" -X GET https://192.168.1.100:7345/menu_native/dynamic/tv_settings/devices/current_input
This will return a JSON string with some info:
{"STATUS":{"RESULT":"SUCCESS","DETAIL":"Success"},"URI":"/menu_native/dynamic/tv_settings/devices/current_input","PARAMETERS":{"HASHONLY":"FALSE","FLAT":"TRUE","HELPTEXT":"FALSE"},"ITEMS":[{"CNAME":"current_input","TYPE":"T_STRING_V1","NAME":"Current Input","VALUE":"HDMI-1","ENABLED":"FALSE","HIDDEN":"TRUE","HASHVAL":2129379411}],"HASHLIST":[222710829,1702838742]}
If this can be returned as a string, that might work. In myServer5, there were some string functions that could be use to parse the string. For this particular instance, I'm looking for the data from HASHVAL so that I can use it on a subsequent call.
Thanks
Please Log in to join the conversation.
- andrew
- Offline
- User
-
Less
More
- Posts: 339
- Thank you received: 28
2 years 4 months ago #1575
by andrew
Replied by andrew on topic Run Curl command in a macro
Maybe let the user specify a regex to capture part of the response, and a server variable name to store it in? This would also be useful for doing http GETs and http POSTs where some data is returned. In fact it would enable full two-way control of some things such as my Yamaha AV amp.
Andrew
Andrew
Please Log in to join the conversation.
- davep
- Offline
- Admin
-
Less
More
- Posts: 367
- Thank you received: 96
2 years 4 months ago #1596
by davep
Replied by davep on topic Run Curl command in a macro
The server I just released
1) Modifies the Run command to add an additional third parameter that will receive the output of the command for further processing.
Run|Program~Parameters~resultsVariable
2) Adds a new command called RunParseResults
RunParseResults|Program~Parameters~ResultsVariable
I tested RunParseResults using your previous json response as its output using RunParseResults|curl~params~foobar and this is what server variables were created. Probably a bit overkill but perhaps useful.
1) Modifies the Run command to add an additional third parameter that will receive the output of the command for further processing.
Run|Program~Parameters~resultsVariable
2) Adds a new command called RunParseResults
RunParseResults|Program~Parameters~ResultsVariable
I tested RunParseResults using your previous json response as its output using RunParseResults|curl~params~foobar and this is what server variables were created. Probably a bit overkill but perhaps useful.
The following user(s) said Thank You: bowlingbeeg
Please Log in to join the conversation.
- andrew
- Offline
- User
-
Less
More
- Posts: 339
- Thank you received: 28
2 years 4 months ago #1599
by andrew
Replied by andrew on topic Run Curl command in a macro
Parsing json into variables - didn't think of that. I'll have to have a play with my Yamaha AV amp, see if I can turn this into a 2-way communications mechanism.
Andrew
Andrew
Please Log in to join the conversation.
Time to create page: 0.179 seconds