2

If I wanted to get, say, usage data about 'calls-inbound' AND 'sms-inbound', you'd think you could just pass an array in as the category param like so.

$records = $client->usage->records->read(
    array(
        "category" => array("calls-inbound","sms-inbound")
        "startDate" => "2012-09-01",
        "endDate" => "2012-09-30"
    )
);

But this only returns data on the first array item "calls-inbound". Any way to get data about more than one category but not all categories?

1 Answers1

1

Twilio developer evangelist here.

The documentation on filtering usage records by category states that adding a category will "only include usage of this usage category."

Category in this case is not a filter you can use with a list of categories, just a single category at a time.

So, in order to get just 2 categories to work with you have 2 choices. You can either make the request and fetch all the categories, then filter for the 2 that you are interested in. Or you can make 2 separate calls to the API, one for the first category and one for the second.

Let me know if that helps.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • 2
    It does help, thanks. But it seems awfully inefficient. Making a request for all categories takes close to 3 seconds per subaccount. Making a request for a single category takes ~400ms. So it would seem helpful to provide a way to retrieve only a few categories at a time. Thanks for the response. – George Böhnisch Dec 17 '17 at 21:04
  • I've raised it internally, but I can't promise that will cause anything in the near future. In the meantime, I'd probably ensure that when I retrieved usage records I did it in a background job so that the length of the request doesn't affect the user facing application. That way it might be more reasonable to make the full request and cache it yourself for future viewing. – philnash Dec 19 '17 at 01:30
  • 1
    3 years later... still looking for a way to do this. I want to report on, for example, an account's SMS and local number breakdown, but nothing else. So I want to do `?Category=sms,mms,phonenumbers` but I can't. – qJake May 07 '20 at 19:58
  • Sorry this hasn't changed @qJake. But like I say in the answer, you can pull all the data and then filter as a workaround. – philnash May 08 '20 at 02:11