How to get customer id by phone number in magento 2.4 login api

640 views Asked by At

I am new in magento api developement for mobile app. I have to write API code for login. This application login has no password and login by mobile phone otp verification. During my coding, I can access customer id by email.

     $customer = $this->customerFactory->create();
     $customer->loadByEmail($email);
     $customerId = $customer->getId();

But I need to access this customer id by phone number,instead of this. What will be the code for 'loadbyphone'?

1

There are 1 answers

0
Niranjan Gondaliya On

We can do it following way. But make sure Phone number is unique.

$customer = $this->customerFactory->create();
$customer->load($telephone_number,'telephone_number');
$customer->getData();