withdraw endpoint return error -1102 - PHP script

Hi guys,
I have a serious problem with withdraw endpoints. My php script works with other endpoints very well, but on withdraw endpoint I get this error:
{“code”:-1102,“msg”:“Mandatory parameter ‘amount’ was not sent, was empty/null, or malformed.”}

Please help me.
Thanks.

<?php
$api_key = 'XXXX';
$secret_key = 'YYYY;
$params = [];

$params['coin'] = "USDT";
$params['address'] = "TXxxx";
$params['network'] = "TRX"; 
$params['amount'] = 20; 
$query = http_build_query($params, '', '&');

date_default_timezone_set('UTC');
$params['timestamp'] = number_format(microtime(true)*1000,0,'.','');
$query = http_build_query($params, '', '&');
$signature = hash_hmac('sha256', $query, $secret_key);
$endpoint = "https://api.binance.com/sapi/v1/capital/withdraw/apply";
$params['signature'] = $signature; // signature needs to be inside BODY
$query = http_build_query($params, '', '&'); // rebuilding query
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_USERAGENT, "User-Agent: Mozilla/4.0 (compatible; PHP Binance API)");
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array(
    'X-MBX-APIKEY: ' . $api_key,
));

curl_setopt($curl_handle, CURLOPT_URL, $endpoint . '?' . $query);
curl_setopt($curl_handle, CURLOPT_POST, true);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $query);
curl_setopt($curl_handle, CURLOPT_HEADER, false);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($curl_handle);
curl_close($curl_handle);
error_log(print_r($res,true)); 
?>

query => coin=USDT&address=TXxxx&network=TRX&amount=20&timestamp=1627136382958&signature=8040054c1abfxxx5281fd34f8

Hi,

The issue is that you are appending the querystring twice to the url.

curl_setopt($curl_handle, CURLOPT_URL, $endpoint . ‘?’ . $query);

and

curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $query);

Removing the appended query string from the first quoted line should do the trick.

curl_setopt($curl_handle, CURLOPT_URL, $endpoint);

1 Like

Thanks Alex.
My problem resolved and the script works fine.
Thanks again and have a good time.

1 Like