how do i get messages count?

426 views Asked by At

I am using Twilio PHP library.

I would like to get the total count of messages available in an account.

I use the following code:

$client = new Services_Twilio($AccountSid, $AuthToken); 
$messages = $client->account->messages ;
echo count($messages);

The count always displays as one (1). Let me know how to get the total count.

Thanks.

1

There are 1 answers

1
Devin Rader On

Twilio evangelist here.

I'd suggest using a Usage Record to get this information:

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACed732a3c49700934481addd5ce1659f0"; 
$token = "{{ auth_token }}"; 
$client = new Services_Twilio($sid, $token);

// Loop over the list of records and echo a property for each one
$callRecord = $client->account->usage_records->getCategory('sms');
echo $callRecord->usage;

Hope that helps.