SHUred
(SHUred)
March 1, 2021, 7:05pm
1
Sorry to open another topic regardings curl and executeCommandLine
I now tried so many variations … i dont get it working
In terminal executed this
curl -H "X-CMC_PRO_API_KEY: MYPERSONALKEY" -H "Accept: application/json" -d "amount=1&symbol=ETH&convert=EUR" -G https://pro-api.coinmarketcap.com/v1/tools/price-conversion
returns
{"status":{"timestamp":"2021-03-01T18:31:47.530Z","error_code":0,"error_message":null,"elapsed":19,"credit_count":1,"notice":null},"data":{"id":1027,"symbol":"ETH","name":"Ethereum","amount":1,"last_updated":"2021-03-01T18:30:03.000Z","quote":{"EUR":{"price":1260.4932810006726,"last_updated":"2021-03-01T18:31:03.000Z"}}}}
i tried stuff like
var String ether = executeCommandLine("curl -H \"X-CMC_PRO_API_KEY: KEYKEY\" -H \"Accept: application/json\" -d \"amount=1&symbol=ETH&convert=EUR\" -G https://pro-api.coinmarketcap.com/v1/tools/price-conversion")
var String ether = executeCommandLine("curl@@-H@@\"X-CMC_PRO_API_KEY: KEYKEY\"@@-H@@\"Accept: application/json\"@@-d@@\"amount=1&symbol=ETH&convert=EUR\"@@-G@@https://pro-api.coinmarketcap.com/v1/tools/price-conversion")
Can someone try to help me to get this working?
Im not a very advanced user.
Afterwards i think i can pick out the JSON $.data.quote.EUR.price number by myself
1 Like
rossko57
(Rossko57)
March 1, 2021, 7:14pm
2
What version of openHAB are you running? It’s no use trying old OH2 examples in OH3, for instance.
rlkoshak
(Rich Koshak)
March 1, 2021, 7:37pm
4
The executeCommandLine Action changed for OH 3. Actions | openHAB . Each argument to the command is a separate argument to executeCommandLine now. No more @@
. And if you actually want the result, you have to supply the timeout Duration.
1 Like
SHUred
(SHUred)
March 1, 2021, 7:49pm
5
I also tried the comma separated Version but did Not exactly know how to handle the " and Spaces in Strings
But i will try again tomorrow and give Feedback
Thanks
NorbertHD
(Norbert Schulze)
March 1, 2021, 8:14pm
6
Please try
var String ether = executeCommandLine(Duration.ofSeconds(5), "curl", "-H", "X-CMC_PRO_API_KEY: KEYKEY", "-H", "Accept: application/json", "-d", "amount=1&symbol=ETH&convert=EUR", "-G", "https://pro-api.coinmarketcap.com/v1/tools/price-conversion")
1 Like
SHUred
(SHUred)
March 2, 2021, 3:35pm
7
I have to say thank you!
@rlkoshak
The timeout-duration was the thing i was missing all the time!
In another post of yours i already found the info regardings the comma-separated synthax
@NorbertHD
Thanks for taking the time and providing the final solution
Works perfect now for me
SHUred
(SHUred)
March 2, 2021, 4:58pm
8
Sorry one last question:
Its normal that the executeCommandLine now returns some sort of header:
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 323 0 323 0 0 1218 0 --:--:-- --:--:-- --:--:-- 1218 {"status":{"timestamp":"2021-03-02T16:51:45.669Z","error_code":0,"error_message":null,"elapsed":33,"credit_count":1,"notice":null},"data":{"id":1027,"symbol":"ETH","name":"Ethereum","amount":1,"last_updated":"2021-03-02T16:50:03.000Z","quote":{"EUR":{"price":1261.1368697478365,"last_updated":"2021-03-02T16:51:02.000Z"}}}}
So to be able to use JSON-transformation for getting my $.data.quote.EUR.price out of it i think i will use the following procedure
curl information
regex: ignore everything before the first “{”
JSON-transformation $.data.quote.EUR.price
Due to my limited skills im not sure if there is an easier way
(Maybe for others reading this topic its also helpful)
Thanks a lot
rlkoshak
(Rich Koshak)
March 2, 2021, 5:38pm
9
That comes from curl. There is an option to suppress it but I don’t know it off the top of my head.
1 Like
SHUred
(SHUred)
March 2, 2021, 6:15pm
10
You are the man! → -s for “silent” does the job
I could have found this by myself
So for beginners like me, here is the working code:
// Example response
// {"status":{"timestamp":"2021-03-01T18:31:47.530Z","error_code":0,"error_message":null,"elapsed":19,"credit_count":1,"notice":null},"data":{"id":1027,"symbol":"ETH","name":"Ethereum","amount":1,"last_updated":"2021-03-01T18:30:03.000Z","quote":{"EUR":{"price":1260.4932810006726,"last_updated":"2021-03-01T18:31:03.000Z"}}}}
// Get JSON
var String ether = executeCommandLine(Duration.ofSeconds(5), "curl", "-s", "-H", "X-CMC_PRO_API_KEY: YOURPERSONALKEY", "-H", "Accept: application/json", "-d", "amount=1&symbol=ETH&convert=EUR", "-G", "https://pro-api.coinmarketcap.com/v1/tools/price-conversion")
// Get Price
ether = transform("JSONPATH","$.data.quote.EUR.price", ether)
// Write to Item
Price_ETH.sendCommand(ether)
system
(system)
Closed
April 13, 2021, 10:15am
11
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.