-1

Trying to get a list of cashbooks from API, but always comes back with ( "Message":"Authorization has been denied for this request."). I'm positive the subscription key is right, I can get the access and refresh tokens, and the user I login to the identity server with has access to multiple cashbooks. And if I login to the azure developer portal and use the "Try Me" test for "Get Cashbooks" it works. Can anyone help?

This is my code:

$subscription_key = '<<SUBSCRIPTION-KEY>>';
$url = 'https://api.reckon.com/R1/cashbooks?subscription-key=' . $subscription_key;
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Bearer' . $access_token;
$header[] = 'Ocp-Apim-Subscription-Key' . $subscription_key;
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 2);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($curl);
curl_close($curl);
echo $response;

2 Answers2

0
$header[] = 'Authorization: Bearer' . $access_token;

There is probably supposed to be a space between "Bearer" and your token.

Similarly:

$header[] = 'Ocp-Apim-Subscription-Key' . $subscription_key;

There is probably supposed to be a colon and space between "-Key" and your key.

0

The answer was so simple. I just had it in the wrong part of the page. Everything was in the body, where i needs to be in the header. I just moved everything up to curl_close($curl) to the head, and response in the body and got my response.

But thanks for your responses both helped me. I did add Bearer, and spaces as suggested, and when that didn't work I eventually realised what I was doing wrong.