Looks like your payload is actually $postdata instead of $parameters?
$response = Http::withHeaders($headers)
->post('https://api.kraken.com/0/private/Balance', $postdata);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I try to convert a curl request to Laravel http Client.
My problem is that the curl call works, but the one with the http client gives an API error.
Curl:
$nonce = explode(' ', microtime());
$nonce = $nonce[1] . str_pad(substr($nonce[0], 2, 6), 6, '0');
$parameters = [
'nonce' => $nonce,
];
$postdata = http_build_query($parameters, '', '&');
$path = '/0/private/Balance';
$sign = hash_hmac('sha512', $path . hash('sha256', $nonce . $postdata, true), base64_decode($apiSecret), true);
$headers = [
'API-Key: ' . $apiKey,
'API-Sign: ' . base64_encode($sign),
'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.kraken.com/0/private/Balance');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
dd($res);
http Client (Replace only the curl part)
$connection = Http::withHeaders($headers);
$response = $connection->post('https://api.kraken.com/0/private/Balance', $parameters);
dd($response->json());
I just don't see my mistake
I don't know if it might be your signing that's off but this got the correct JSON response for me.
$headers = [
'API-Key' => config('services.kraken.key'),
'API-Sign' => base64_encode(
hash_hmac(
'sha512',
'/0/private/Balance' . hash('sha256', $nonce . http_build_query($parameters), true),
base64_decode(config('services.kraken.secret')),
true,
)
)
];
$response = Http::withHeaders($headers)
->asForm()
->post('https://api.kraken.com/0/private/Balance', $parameters);
dd($response->json());
Here dd returns the expected JSON response data.
{"error":[],"result":{}}
Also, make sure your API Key has the correct permission to Query funds.
Please or to participate in this conversation.