I'm trying to get a list of all the workers on a Twilio account but am unable to do so.
Here's my code:
<?php
// Required if your environment does not handle autoloading
require __DIR__ . '/vendor/autoload.php';
// Your Account SID and Auth Token from console.twilio.com
$sid = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
$token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
$client = new Twilio\Rest\Client($sid, $token);
$workspace = $client->taskrouter->v1->workspaces('WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
foreach ($workspace->workers as $worker) {
print_r($worker);
}
When I run that I don't get any output at all. In console.twilio.com I can see that I have 5 workers in the workspace corresponding to the WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa sid but the above code isn't showing them.
I adapted the above code from https://www.twilio.com/docs/taskrouter/api/worker#read-multiple-worker-resources
Any ideas?
From the documentation, it seems you have to call the read method
<?php
$workers = $client->taskrouter->v1
->workspaces("WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
->workers
->read([], 20);
foreach ($workers as $worker) {
print_r($worker);
}