helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API
MIT License
98 stars 62 forks source link

Just a question: How do I get the customer ID from her/his email #285

Closed utrenkner closed 2 years ago

utrenkner commented 2 years ago

I have the customer's email and want to retrieve her/his customer ID.

I can list the customer with

$filter = (new CustomerFilters())
        ->withQuery('email:"my@email.test');

    $customers = $client->customers()->list($filter);

But how would I query the resulting $customers (of type PagedCollection) so that I can identify the ID? The direct way is not possible because ID is private. But I do not find a suitable getter function...

miguelrs commented 2 years ago

Hi @utrenkner!

There is a section in the README file that explains how to deal with Pagination.

Also, the Customer class has a getId() method you can use.

So, once you have your $customers collection, you just need to do something like:

foreach ($customers as $customer) {
    $customerId = $customer->getId();
    // ...
}

Hope that helps!

utrenkner commented 2 years ago

Thank you @miguelrs !