More
referral
Increase your income with Hive. Invite your friends and earn real cryptocurrency!

Hive API v2

Hi everyone,

How can I run the command line by the API?

Cheers

Hello,

I try to make a mix withe the different posts to make my API.
But I’m wrong in the array to declare.

Somebody can help me ?
The connexion is OK, and I get the error :

{
“message”: “Method Not Allowed”,
“code”: 405
}

I want to make a script for stop or start the miners.

Thanks

<?php
$baseUrl = 'https://api2.hiveos.farm/api/v2';
$data = array();

$data['command'] = "miner";
$data['data']['action']="stop";

//$data2=  array('command'=>'miner','data'=>array('action'=>'stop'));
//$data2['miner'][0]['exec'] = "shutdown";



  $url = "$baseUrl/farms/######/workers/######/command";
  // --> https://api2.hiveos.farm/api/v2/farms/######/workers/######

$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "accept: application/json";
$headers[] = "Authorization: Bearer ########################";

$ch = curl_init($url);
curl_setopt_array($ch, [
  CURLOPT_HTTPHEADER => $headers,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "PATCH",
  CURLOPT_POSTFIELDS => json_encode($data),
]);
$res = curl_exec($ch);
//$farms = $res['data'];
print_r($res);


?>

on my side , this is my array structure =>

{
  "worker_ids": [
    1234567
  ],
  "search_id": null,
  "data": {
    "command": "miner",
    "data": {
        "action":"stop"
    }
  }
}',

In first, thanks a lot for the quick answer.

I’m not an expert with php and can you tell me more informations ?

Is it possible to have the complete delaration ?

I try

$data2={
  "worker_ids": [
    123XXXXXX
  ],
  "search_id": null,
  "data": {
    "command": "miner",
    "data": {
        "action":"stop"
    }
  }
}',

but it’s not working…

I think a user a bad declaration of this array.

Thanks !

It’s good now but I have :

{
“message”: “Method Not Allowed”,
“code”: 405
}

I use
$baseUrl = ‘https://api2.hiveos.farm/api/v2’;
$url = “$baseUrl/farms/XXX/workers/YYYYY/command”

I use
“worker_ids”: [
YYYYY
],

Thanks

It’s good !!!

I share my code for help the others newbie dev like me :slight_smile:


<?php
$baseUrl = 'https://api2.hiveos.farm/api/v2';
$data = array();

$data = json_decode('
{
  "worker_ids": [
    "WORKER_ID"
  ],
  "search_id":null,
  "data": {
    "command": "miner",
    "data": {
        "action":"restart"
    }
  }
}');



  $url = "$baseUrl/farms/FARM_ID/workers/command";
  // --> https://api2.hiveos.farm/api/v2/farms/######/workers/######

$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "accept: application/json";
$headers[] = "Authorization: Bearer YOUR_API_KEY_HERE

$ch = curl_init($url);
curl_setopt_array($ch, [
  CURLOPT_HTTPHEADER => $headers,
  CURLOPT_RETURNTRANSFER => true,
//  CURLOPT_CUSTOMREQUEST => "PATCH",
  CURLOPT_POSTFIELDS => json_encode($data),
]);
//print_r(json_encode($data));
$res = curl_exec($ch);
//$farms = $res['data'];
print_r($res);

?>

Thanks for all

1 Like

Do you have a working version, I can’t seem to get any connection. have basic PHP :slight_smile:

My code works for me.

Regards.

I used what you put above and nothing happens, i just need to get unpaid ETH, can you help :slight_smile:

Do you change the YOUR_API_KEY_HERE and the number for farmers/workers with yours ? What is the answer of the API ($res) ?

To have a YOUR_API_KEY_HERE you must create an API application in your settings.

Regards,

you have lines commented out, is that correct?, like

// CURLOPT_CUSTOMREQUEST => “PATCH”,

//$farms = $res[‘data’];

//print_r(json_encode($data));

// → https://api2.hiveos.farm/api/v2/farms/1/workers/4

I get { “message”: “Not Found”, “code”: 404 }

I think you may have a bad url or a bad API_KEY.

Could you please tell me where can I find the security code?
First of all, my 2FA is turned off but my webpage response is that a security code is required, when I introduce one in the headers as you did here, it says it is wrong. Where is the correct one?

I have also used my token from account settings with my credentials.

I’ve been attempting to log in with my api authorization key. But it doesn’t appear to be allowing me access? Is there more steps then ensuring Authorization: is in the header of the api call? Very new to api’s I apologize if this is a stupid question, attempting to teach myself.

I am doing this fine in node red - make sure you have the word bearer in the authorization area - it seems lots of people keep missing this

what i did

  1. Login to web ui
  2. Go to settings under your account name (top right hand corner and right click for dropdown)
  3. Scroll down to Authentication tokens and generate new API token
  4. Copy that to your clipboard (i use windows)
  5. Open up a putty session to a Linux machine (or your miner)
  6. Copy in the following code

curl -s -w ‘\n%{http_code}’ -H ‘Content-Type: application/json’ -H ‘Authorization: Bearer YOUR_API_KEY_HERE’ https://api2.hiveos.farm/api/v2/farms/YOUR_FARM_ID_HERE

Craig

Зачем изменили страницу входа в ферму? Теперь она то и дело вываливается в logoff, на страницу авторизации(!), при этом при вводе логин - пароль(!), получаешь сообщение, что вас долго не было и снова показывает туже страницу авторизации(!). Приходится второй раз вводить логин и пароль, ну и код 2FA.
Это очень раздражает!

а API всё? Сломали с концами? Ничего не работает неделю

@hiveon, @keaton_hiveon, the API has not been working for several days, for any request I get a response “Unauthorized”. Even a page https://api2.hiveos.farm/api/v2/ is not working

Please FIX API
@hiveon @keaton_hiveon