I want to create a bash script for this, but I’m fairly novice at scripting. How would I get these into variables and post via curl?? Output is returned in json format. I see there is a JSON parser which looks fairly simple to use https://stedolan.github.io/jq/ (eg: jq ‘.access_token’) will take the value of access_token from the JSON output
I’ve tested this, by manually pasting the first 2 into a web browser (the first I have to click ‘Allow’), and obtaining the output with the final command run at CLI to test turning the AC on or off. I just need to convert to a Linux script and use exec binding to run!
Basically, the process is as follows:
Get code from Ambiclimate API
https://api.ambiclimate.com/oauth2/authorize?client_id=MY_CLIENT_ID&redirect_uri=https%3A%2F%2Fhttpbin.org%2Fget&response_type=code
RESPONSE:
{
"args": {
"code": "MY_ACCESS_CODE"
},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9,de;q=0.8,da;q=0.7",
"Cache-Control": "max-age=0",
"Connection": "close",
"Host": "httpbin.org",
"Referer": "https://api.ambiclimate.com/oauth2/authorize?client_id=MY_CLIENT_ID&redirect_uri=https%3A%2F%2Fhttpbin.org%2Fget&response_type=code",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
},
"origin": "public_ip",
"url": "https://httpbin.org/get?code=MY_ACCESS_CODE"
}
Get Token (using the Code) from Ambiclimate API
https://api.ambiclimate.com/oauth2/token?client_id=MY_CLIENT_ID&redirect_uri=https%3A%2F%2Fhttpbin.org%2Fget&code=MY_ACCESS_CODE&client_secret=MY_SECRET&grant_type=authorization_code
RESPONSE:
{"access_token": "MY_ACCESS_TOKEN", "token_type": "Bearer", "scope": "email device_read ac_control", "expires_in": 144000, "refresh_token": "MY_REFRESH_TOKEN"}
Tell Ambi to, for example, turn on comfort mode via Ambiclimate API
From Linux CLI, turn on comfort mode:
curl -X GET -G -H “Accept: application/json” -H “Authorization: Bearer MY_ACCESS_TOKEN” “https://api.ambiclimate.com//api/v1/device/mode/comfort”
RESPONSE:
[
{
"device_online": true,
"location": "Home",
"room_name": "Bedroom ",
"status": "ok",
"status_code": 200
}
]
Could anyone offer some linux scripting assistance here?!!!
Doc’s are here. https://api.ambiclimate.com/doc/api
Cheers