i think it desnt work. still getting:
“message”:“The given data was invalid.”,“errors”:{“login”:[“The login field is required.”],“password”:[“The password field is required.”]}
have you gotten it to work?
i think it desnt work. still getting:
“message”:“The given data was invalid.”,“errors”:{“login”:[“The login field is required.”],“password”:[“The password field is required.”]}
have you gotten it to work?
Which endpoint are you testing on ?
How do you call the API ? Curl ?
I can send you an example
curl --location --request GET 'https://api2.hiveos.farm/api/v2/farms/12345/workers/1234567' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer yourAPItoken'
I can login with the API, but I have an issue with the code when I try to stop an specific worker. Who can spot my mistake?
function stopMinning() {
return fetch(`${baseUrl}/farms/${farm}/workers/${workerId1}/command`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'accept': 'application/json',
'Authorization': `Bearer ${token}`,
},
body: JSON.stringify(
{
"command": "stop"
}
)
}).then(r => {
if (!r.ok) {
r.json().then(data => {
console.error(data.message || 'Response error');
});
return Promise.reject(r);
}
else {
return r.json();
}
});
}
it works now, The correct body is
body: JSON.stringify({
'command': 'miner',
'data': {'action': 'stop'}
})
Thanks that solved it!
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
<?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
Do you have a working version, I can’t seem to get any connection. have basic PHP
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
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));
I get { “message”: “Not Found”, “code”: 404 }