[DEPRECATED] Hive API

Hive API. Let’s call Ey Pi Ay)

Go to your Account
https://hiveos.farm/a/account/#pane-user
At the bottom you will be able to generate API keys. Save them.


Authentication
Every API call has a SHA-256 HMAC signature generated with your secret key. Our server generates it’s own HMAC signature and compares it with the API caller’s. If they don’t match the API call is discarded. The HMAC signature is sent as a HTTP header called ‘HMAC’.

The HMAC signature is created from the full raw POST data of your request.
Field “public_key” with your public key should be included in the request.
Example of your POST raw data:

method=getRigs&public_key=<your public key>

and the HMAC sha256 would be something like “db8c07bc43c7ca12b3df1cd5d46ad3ec76b772158f279a1c7a1eb3b45722be69” which you create with your secret key.

Then you add this hmac hash to HTTP header “HMAC: db8…” and make a HTTP POST with all this stuff.

POST URL is:

https://api.hiveos.farm/worker/eypiay.php

API Response

Responses fool the JSON RPC API http://www.jsonrpc.org/specification
So you will have “error” in json if something fails

{"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "id": null}

Or a valid response with “result” field in it:

{"jsonrpc": "2.0", "result": {"your precious data": "lalala"}, "id": null}

API methods

getWallets - get all your wallets data

getOC - get all your Overclocking profiles

getRigs - get the list of your rigs

getCurrentStats - get current monitor data

multiRocket - apply settings to multiple rigs. This method has extra parameters (POST fields). At least one is required.
[list]
[] rig_ids_str - coma separated string with rig ids “1,2,3,4”
[
] miner - Miner to set. Leave it null if you do not want to change. “claymore”, “claymore-z”, “ewbf”, …
[] miner2 - Second miner to set. Leave it null if you do not want to change. “0” - if you want to unset it.
[
] id_wal - ID of wallet. Leave it null if you do not want to change.
[*] id_oc - ID of OC profile. Leave it null if you do not want to change.
[/list]
So the request will look like

method=multiRocket&rig_ids_str=1,2,3&miner=claymore&public_key=<your public key>

Code examples are attached.

  • PHP
  • Python
  • Java

If you can do other languages please send them here or with email.

— reserved —

Ура УРА УРА !!! вперед делать приложухи :slight_smile:

[quote=“DimaFern;640”][/quote]

Any chance of adding the rig local ip to the status response?

Actually I’ve just found it in GetRigs so no worries.

I’m trying the API using the Requests python package without success. API always returning “method no given”.

{
  "error": {
    "code": -32601, 
    "message": "method not given"
  }, 
  "id": null, 
  "jsonrpc": "2.0"
}

It would be nice to add some Python code example, as I’m not able to use the api with python.

Here come’s the snippet i’m using with python. I’m sure that i’m doing something wrong, but dunno whats wrong…

The HMAC generating OK, i’m passing OK the params trought the request.post function, but API still saying no method issued. So weird.


def minerStatsHiveOS():
	api_key = 'api_key'
	secret_key = 'secret_key'

	import requests, json, datetime, hmac, hashlib, urllib, pycurl

	url = 'https://api.hiveos.farm/worker/eypiay.php'
	method = 'getRigs'
	payload = {'public_key': api_key, 'method': method}
	hmac_value = hmac.new(key=secret_key, msg=urllib.urlencode(payload), digestmod=hashlib.sha256).hexdigest()
	
	print hmac_value

	headers = {'HMAC': hmac_value}

	resp = requests.post(url=url, params=payload, headers=headers)
	data = json.loads(resp.text)
	
	return make_response(jsonify(data), 200)

Ok. Now I see there are new python examples (they weren’t first day the post came up). So it’s working okay with CURL but no with Requests… Weird…

@dawy you are sending a POST request, you probably need to send a GET. Change requests.post to requests.get and see if it works :slight_smile:

Hi! Great work.
Need to return Red Temp value, I suggest it must be in getCurrentStats method.
I need it to check temp and fans (I make a telegram bot)

В python скрипте на 193 строке нужно заменить return ocs на return stats

fixed. thanks.

red temp is added into new field user.red_temp

I’m sending a POST request to https://api.hiveos.farm/worker/eypiay.php?method=getCurrentStats&public_key=<public_key> with Postman.app

And I keep getting:

{
  "error": {
  "code": -32601, 
  "message": "method not given"
  }, 
  "id": null, 
  "jsonrpc": "2.0"
}

HMAC generation is OK.

I get it now, I need a pre-request script to generate the HMAC sha256 signature. Anyone have an example in JS?

very nice! thanks for this enhancement!

Отлично! спасибо, пробуем…

function for calculate hmac value on android


static String HmacValue(String key, String data) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException, DecoderException {

        String returnString = "";
        try {
            SecretKeySpec secret_key = new SecretKeySpec(key.getBytes(UTF_8), "HmacSHA256");
            Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
            sha256_HMAC.init(secret_key);
            returnString = new String(Hex.encodeHex(sha256_HMAC.doFinal(data.getBytes("UTF-8"))));
            Log.w(LOG_TAG,"retSrng "+returnString);

        }catch (Exception e){
            Log.e(LOG_TAG,"err in hmac encoding");
            e.printStackTrace();
        }
        return returnString;
    }

@DimaFern, may be possible to implement create QR-Code with secret and public key in personal account?

Хотел бы сделать клиентское приложение на nativeScript, но для этого нужно вам настроить сервер на Cross-Origin Resource Sharing (CORS), иначе из localhost’a отправляется сначала запрос OPTIONS, сервер отвечает отказом (не настроен получать такой метод) и собственно POST не отправляется.
И сколько я не мучался отправлять разные запросы с разными параметрами и даже танцевал голый с бубном, ошибка одна и та же -32601
Поделитесь запросом на JS (axios)

fixed. thanks.

red temp is added into new field user.red_temp[/quote]

Спасибо, свойство red_temp вижу,
но оно всегда приходит как “{” http://forum.hiveos.farm/uploads/editor/5k/fngwi11ufxdr.png

Также хочу попросить возвращать значение баланса лицевого счета, в виде свойства balance в секции user

I make my own code for nodejs / express , not complete but its work


var express = require('express');
var router = express.Router();
var request = require('request');
var CryptoJS = require("crypto-js");

/* GET home page. */
router.get('/api/:public_key/:secret_key/:method', function (req, res, next) {
  var key = req.params.secret_key;
  var data = 'public_key='+req.params.public_key+'&method='+req.params.method;

  var hash = CryptoJS.HmacSHA256(data, key);  
  const myhmackey = hash.toString();

  var options = {
    url: 'https://api.hiveos.farm/worker/eypiay.php',
    headers: {
      'HMAC': myhmackey,
      'content-type': 'application/jso'
    },
    form: {
      public_key: req.params.public_key,
      method: req.params.method
    }
  };

  function callback(error, response, body) {
    //process.stdout.write(getHash(data))

    console.log(body)
    if (!error && response.statusCode == 200) {
      var info = JSON.parse(body);
      var re = info;  
      res.json({
        success: true,
        data: re.result,
    })    
     
    }
  }
  


  request.post(options, callback);
 
});

module.exports = router;

вопрос такой. Как отключить 2-ую аутентификацию если потерял телефон и номер