Search code examples
phptwilio-php

How do you list queue members with Twilio PHP SDK


I have been trying for hours to list out Twilio hold queue members with their hold times, etc, etc without success using the Twilio PHP sdk/helper.

The very basics of my code:

$twilio = new Client($sid,$token);
$queues = $twilio->queues('QUXXXXXXX')->members('')->fetch();

I could put a call Sid in members() but I need the list of call Sids. If I leave it empty doing a var_dump shows me that there is a [queue_members] elemnet that has all the array elements with the data I need in it, but I cant figure out for the life of me how to get at it. I would think this this would be easy, and it probably is, but Im not able to translate Twilio's documentation into what else would work in this scenario that I havent already tried 10 different ways.

I am trying to learn the Twilio PHP wrapper, as I am pretty familiar with using their API using just curl.

Thanks


Solution

  • Access the members property of the queue.

    This is of the Queue\MemberList type.

    Then either read or stream member instances from it.

    The following code snippet logs the uri property of the Queue\MemberInstance. Look up other accessible properties in the docs.

    # Read example
    $members = $twilio->queues('QUx')->members->read();
    
    foreach($members as $member) {
        echo $member->uri;
    };
    
    # Stream example
    $memberStream = $twilio->queues('QUx')->members->stream();
    
    foreach($memberStream as $member) {
        echo $member->uri;
    };