I'm having issues figuring out how to access the response from the following API request. Whilst the public API is simple and returns JSON that I can throw into object/array, I'm not quite understanding how to access the response of the request with API keys .etc. Ultimately I would like to be able to access items in a similar way to the public API:
$contents = file_get_contents($url);
$json = json_decode($contents, true);
//PRINT IT
echo $json['something']['something'];
This is the code supplied in the development API docs:
$apikey = "xxx";
$apisecret = "yyy";
$nonce=time();
$uri='https://bittrex.com/api/v1.1/account/getbalances?apikey='.$apiKey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult);
If I try and dump $obj, it returns '1'.
//DEBUGGING
echo '<pre>';print_r($obj);exit;
This is what the response should look like:
{
"success" : true,
"message" : "",
"result" : [{
"Currency" : "DOGE",
"Balance" : 0.00000000,
"Available" : 0.00000000,
"Pending" : 0.00000000,
"CryptoAddress" : "DLxcEt3AatMyr2NTatzjsfHNoB9NT62HiF",
"Requested" : false,
"Uuid" : null
}, {
"Currency" : "BTC",
"Balance" : 14.21549076,
"Available" : 14.21549076,
"Pending" : 0.00000000,
"CryptoAddress" : "1Mrcdr6715hjda34pdXuLqXcju6qgwHA31",
"Requested" : false,
"Uuid" : null
}
]
}
Here's the API documentation: https://bittrex.com/Home/Api
Also, the above code automatically prints the response on the page, what line is printing it all?
I'm quite new to API's so sorry if this is a daft question, I just can't get my head round it.
Thanks
/////RESOLVED
I added the following lines of code and it worked.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);