Hive open API version 2.
New Hive 2.0 has REST API.
Previous API v1 is totally deprecated. ([DEPRECATED] Hive API)
API endpoints are here
https://api2.hiveos.farm/api/v2
Full specification is here
https://app.swaggerhub.com/apis/HiveOS/public/2.1-beta
You authorize with the credentials and receive JWT auth token. Then you can do just anything what you can do in Hive. You can build your autoswitching, get stats data, add/switch wallets, apply OC settings, adopt a mobile version, create a custom monitoring screen.
Extended documentation and how-to tutorials will be later, but you can inspect the requests that new frontend sends since it also works with this API.
Client example: PHP
<?php
$baseUrl = 'https://api2.hiveos.farm/api/v2';
$login = 'your_login';
$password = 'your_password';
function doCurl($ch) {
$res = curl_exec($ch);
if ($res === false) {
die('CURL error: '.curl_error($ch));
}
$code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
$res = json_decode($res, true);
if ($code < 200 || $code >= 300) {
throw new Exception($res['message'] ?? 'Response error');
}
return $res;
}
// 1. Login
$ch = curl_init("$baseUrl/auth/login");
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode([
'login' => $login,
'password' => $password,
]),
CURLOPT_RETURNTRANSFER => true,
]);
$res = doCurl($ch);
$token = $res['access_token'];
// 2. Get farms list
$ch = curl_init("$baseUrl/farms");
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => [
"Authorization: Bearer $token"
],
CURLOPT_RETURNTRANSFER => true,
]);
$res = doCurl($ch);
$farms = $res['data'];
print_r($farms);
Client example: Javascript
const baseUrl = 'https://api2.hiveos.farm/api/v2';
let accessToken = null;
doLogin('your_login', 'your_password')
.then(getFarms)
.then(farms => console.log('farms=', farms));
function doLogin(login, password) {
return fetch(`${baseUrl}/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({login, password})
}).then(r => {
if (!r.ok) {
r.json().then(data => {
console.error(data.message || 'Response error');
});
return Promise.reject(r);
}
else {
return r.json().then(data => {
accessToken = data.access_token;
return data;
});
}
})
}
function getFarms() {
return fetch(`${baseUrl}/farms`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`,
}
}).then(r => {
if (!r.ok) {
r.json().then(data => {
console.error(data.message || 'Response error');
});
return Promise.reject(r);
}
else {
return r.json();
}
});
}
Client example: Bash
#!/bin/bash
baseUrl='https://api2.hiveos.farm/api/v2'
login='your_login'
password='your_password'
# 1. Login
response=`curl -s -w "\n%{http_code}" \
-H "Content-Type: application/json" \
-X POST \
-d "{\"login\":\"$login\",\"password\":\"$password\"}" \
"$baseUrl/auth/login"`
[ $? -ne 0 ] && (>&2 echo 'Curl error') && exit 1
statusCode=`echo "$response" | tail -1`
response=`echo "$response" | sed '$d'`
[[ $statusCode -lt 200 || $statusCode -ge 300 ]] && { echo "$response" | jq 1>&2; } && exit 1
# Extract access token
accessToken=`echo "$response" | jq --raw-output '.access_token'`
# 2. Get farms
response=`curl -s -w "\n%{http_code}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $accessToken" \
"$baseUrl/farms"`
[ $? -ne 0 ] && (>&2 echo 'Curl error') && exit 1
statusCode=`echo "$response" | tail -1`
response=`echo "$response" | sed '$d'`
[[ $statusCode -lt 200 || $statusCode -ge 300 ]] && { echo "$response" | jq 1>&2; } && exit 1
# Display farms
echo "$response" | jq