API Staking endpoint don´t work php

Hello,

I try to get the staking productlist but i didn´t work…

<?php

  $secret = "secretKey";
  $key = "apiKey"; 

  $s_time = "&timestamp=".time()*1000;

  $sign=hash_hmac('SHA256', $s_time, $secret);

  $url = "https://api.binance.com/sapi/v1/staking/productList?product=STAKING".$s_time."&signature=".$sign;

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MBX-APIKEY:'.$key));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_URL, $url);

  $result = curl_exec($ch);
  $result = json_decode($result, true);

  echo '<pre>';
  var_dump($result);
  echo '</pre>';

  curl_close($ch);
?>

Error message:

array(2) {
  ["code"]=>
  int(-1022)
  ["msg"]=>
  string(40) "Signature for this request is not valid."
}

When sign the playload, this &timestamp=15000000000 is incorrect that &in head should not be included.

i did the “&” away now i get this error:

array(2) {
  ["code"]=>
  int(-1102)
  ["msg"]=>
  string(65) "A mandatory parameter was not sent, was empty/null, or malformed."
}

You need to get rid of the .$s_time. from your $url, that’s what causing the malformed product parameter.

Why should i remove the timestamp from the url if it is required?

I tried, the error message is the same…

Where should the timestamp go then?

You have to signed the payload and timestamp. I made variable called query_string and entered the payload and timestamp then signed it. Check this code, it works.

  $s_time = time()*1000;

  $query_string = "product=STAKING&timestamp=".$s_time;
  $sign=hash_hmac('SHA256', $query_string, $secret);
  $url = "https://api.binance.com/sapi/v1/staking/productList?".$query_string."&signature=".$sign;

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MBX-APIKEY:'.$key));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_URL, $url);

  $result = curl_exec($ch);
  $result = json_decode($result, true);
 
  echo '<pre>';
  var_dump($result);
  echo '</pre>';

  curl_close($ch);