bones
bones

Reputation: 81

RingCentral API / PHP SDK Rest

I am working with RingCentral's API attempting to pull the presence status of all users within our account (We have 30). I have checked the RingCentral Admin side and ensured that all have phones have their show presence enabled. I have the following code that is working properly and pulling in the presence status. However, it will only pull in one extension. Is anyone familar with this API and how to query all extensions? Code below: (Like I stated this is working perfectly just only pulling in one extension (the one I am logged on with).

require_once(__DIR__ . '/_bootstrap.php');
use RingCentral\SDK\SDK;

// Create SDK instance
$credentials = require(__DIR__ . '/_credentials.php');
$rcsdk = new SDK($credentials['clientId'], $credentials['clientSecret'], $credentials['server'], 'Demo', '1.0.0');
$platform = $rcsdk->platform();

// Authorize
$platform->login($credentials['username'], $credentials['extension'], $credentials['password']);

// Load extensions  //
$extensions = $platform->get('/account/~/extension', array('perPage' => 10))->json()->records;

// show user count here, only showing a count of 1
print 'Users loaded ' . count($extensions) . PHP_EOL;

$presences = $platform->get('/account/~/extension/' . $extensions[0]->id . ',' . $extensions[0]->id . '/presence')
                  ->multipart();

$presences00 = $platform->get('/account/~/extension/~')
                  ->json();

echo "<textarea style='width:100%;height:500px;'>";
                  print_r($presences00);
                  echo "</textarea>";

print 'Presence loaded ' .
  $extensions[0]->name . ' - ' . $presences[0]->json()->presenceStatus . ', ' .
  $extensions[0]->name . ' - ' . $presences[1]->json()->presenceStatus . PHP_EOL;

Here is the working link to the actual PHP file: http://silkrut.com/william2/vendor/ringcentral/ringcentral-php/demo/ext.php

Ring Central's Documentation: https://devcommunity.ringcentral.com/ringcentraldev/topics/where-could-i-lookup-my-accountid-and-extensionid-st8045nl19xkj Where they state at the bottom " Tyler Long, Official Rep And by the way send a GET request to /restapi/v1.0/account/~/extension to get a list of the extensions in your account."

If anyone can assist or knows where I might be going wrong here, I would greatly appreciate it! Thanks kindly for your time!

Upvotes: 1

Views: 243

Answers (1)

Paco Vu
Paco Vu

Reputation: 211

To get presence for all extensions, you just need to log in with an admin extension then call the Company presence endpoint.

$presences = $platform->get('/account/~/presence');

If you want to get detailed status, remember to add the flag

$presences = $platform->get('/account/~/presence?detailedTelephonyState=true');

Upvotes: 1

Related Questions