简体   繁体   中英

JSON RPC 2.0 API Call using CURL in PHP - Changelly API

I am trying to call changelly API with below codes but it is returning "Unauthorized" in response.

Appreciate if someone can help in identifying the mistake I am making in below code.

$API_URL = 'https://api.changelly.com';
$API_KEY = 'XXXXX';
$API_SECRET = 'XXXXX';

$message = array();
$message['jsonrpc'] = '2.0';
$message['method'] = 'getMinAmount';
$message['params'] = array('from' => 'BTC', 'to' => 'LTC');
$message['id'] ='12345';
$data = json_encode($message);
$sign = hash_hmac('SHA512', $data, $API_SECRET);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_URL);
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json",'Authorization:api-key: '.$API_KEY.':sign: '.$sign));

$final_result = curl_exec($ch); 
curl_close($ch);
echo '<pre>';
print_r($final_result);

Changelly API guide is at https://changelly.com/developers

Thanks

in your code you have wrong set of headers.

please check this example: https://github.com/changelly/changelly-examples/blob/master/php/example.php , hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM