phpapiibeaconestimotebeacon

Estimote API integration


so i've been trying to integrate Estimote API to bring the beacons list to my personal CMS, i'm encountering with the problem that i get "Unauthorised" message i have read through the Api docs and the General - Authorization is the one that i can since i'm bringing the beacons that are in my cloud account, theres an example on a curl request that i can get the list of beacons by doing this:

curl -u app_0a1b2c3d4e:0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d \
     -H 'Accept: application/json' \
     https://cloud.estimote.com/v1/beacons

The problem is that i have been trying to do that and it says that In general i should use App ID and App Token to authorise my requests

header('Content-Type: application/json');

$app_id = "appid";
$token = "token";
$ch = curl_init('https://cloud.estimote.com/v1/beacons?appid='.$appId.'&apptoken='.$token);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));

$result = curl_exec($ch);

print_r($result);
curl_close($ch);

any ideas on what am i doing wrong? https://cloud.estimote.com/docs/#api-Beacons-GetBeacons


Solution

  • What you are doing is trying to send post fields with a get request.

    You can remove this line curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

    In the documentation https://cloud.estimote.com/docs/#api-General-Authorization it says that you need to send your appid as username and token as password. In curl you have that option.

    Try this

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://cloud.estimote.com/v1/beacons');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, "$appid:$token");
    $output = curl_exec($ch);
    curl_close($ch);