cancel
Showing results for 
Search instead for 
Did you mean: 

How to get customer details by telephone Number Magento2 rest Api?

How to get customer details by telephone Number Magento2 rest Api?

 
I have used this end point get request <yoursite.com>/rest/<store_code>/V1/customers/search with the following parameters:
searchCriteria[filterGroups][0][filters][0][field]: addresses[telephone]searchCriteria[filterGroups][0][filters][0][value] : 123456789searchCriteria[filterGroups][0][filters][0][conditionType]: eq

But still not able to get the desire result only error occur as the addresses[telephone] does not field any magento2 rest API expert here.

9 REPLIES 9

Re: How to get customer details by telephone Number Magento2 rest Api?

Hi @devcx9gmai328a 


Try below search query:

searchCriteria[filterGroups][0][filters][0][field]: telephone&
searchCriteria[filterGroups][0][filters][0][value] : 123456789&
searchCriteria[filterGroups][0][filters][0][conditionType]: eq

Also check with you system. Field name is "telephone" or "phone". Change according to field name.

Problem Solved? Please click on 'Kudos' & Accept as Solution!

Problem solved? Click Accept as Solution!

Re: How to get customer details by telephone Number Magento2 rest Api?

Hi @devcx9gmai328a ,

 

According to Vanilla Magento's structure, there is no Customer attribute as Telephone. We have a telephone as a Customer address attribute. This may be the reason behind the issue in the search using Rest API.

 

For Making customer search using Telephone you need to perform the below steps:

1. You need to create a custom attribute like a phone/telephone for the customer entity.

2.  Saving the data in this attribute and enable it for 'Use in Search'.

 

Hope this helps you!

Problem Solved! Click Kudos & Accept as Solution!

Re: How to get customer details by telephone Number Magento2 rest Api?

Thanks for the reply I have tried this solution but getting an error that there is no attribute of telephone in customer. As per metadata of customer telephone exists inside the addresses array so how can I able to search customer via telephone using REST-API ? will wait for you response. 

{
  "id": 0,
  "group_id": 0,
  "default_billing": "string",
  "default_shipping": "string",
  "confirmation": "string",
  "created_at": "string",
  "updated_at": "string",
  "created_in": "string",
  "dob": "string",
  "email": "string",
  "firstname": "string",
  "lastname": "string",
  "middlename": "string",
  "prefix": "string",
  "suffix": "string",
  "gender": 0,
  "store_id": 0,
  "taxvat": "string",
  "website_id": 0,
  "addresses": [
    {
      "id": 0,
      "customer_id": 0,
      "region": {
        "region_code": "string",
        "region": "string",
        "region_id": 0,
        "extension_attributes": {}
      },
      "region_id": 0,
      "country_id": "string",
      "street": [
        "string"
      ],
      "company": "string",
      "telephone": "string",
      "fax": "string",
      "postcode": "string",
      "city": "string",
      "firstname": "string",
      "lastname": "string",
      "middlename": "string",
      "prefix": "string",
      "suffix": "string",
      "vat_id": "string",
      "default_shipping": true,
      "default_billing": true,
      "extension_attributes": {},
      "custom_attributes": [
        {
          "attribute_code": "string",
          "value": "string"
        }
      ]
    }
  ]

Re: How to get customer details by telephone Number Magento2 rest Api?

I am developing Magento integration and I don't have direct access to Magento2 only rest-API to perform crud operation basis on the provided data so what should be filtered look like to search nested object data using rest- services as I directly access customer via email but I need to search the customer based on the telephone. Thanks for the reply will wait for your response. 

{
  "id": 0,
  "group_id": 0,
  "default_billing": "string",
  "default_shipping": "string",
  "confirmation": "string",
  "created_at": "string",
  "updated_at": "string",
  "created_in": "string",
  "dob": "string",
  "email": "string",
  "firstname": "string",
  "lastname": "string",
  "middlename": "string",
  "prefix": "string",
  "suffix": "string",
  "gender": 0,
  "store_id": 0,
  "taxvat": "string",
  "website_id": 0,
  "addresses": [
    {
      "id": 0,
      "customer_id": 0,
      "region": {
        "region_code": "string",
        "region": "string",
        "region_id": 0,
        "extension_attributes": {}
      },
      "region_id": 0,
      "country_id": "string",
      "street": [
        "string"
      ],
      "company": "string",
      "telephone": "string",
      "fax": "string",
      "postcode": "string",
      "city": "string",
      "firstname": "string",
      "lastname": "string",
      "middlename": "string",
      "prefix": "string",
      "suffix": "string",
      "vat_id": "string",
      "default_shipping": true,
      "default_billing": true,
      "extension_attributes": {},
      "custom_attributes": [
        {
          "attribute_code": "string",
          "value": "string"
        }
      ]
    }
  ]  

 

Re: How to get customer details by telephone Number Magento2 rest Api?

Did you eventually find a solution? I am struggling with the same problem.

Re: How to get customer details by telephone Number Magento2 rest Api?

Did you eventually find a solution? I am struggling with the same problem.

Re: How to get customer details by telephone Number Magento2 rest Api?

I am working on a Magento integration where I have access only to the Magento 2 REST API for performing CRUD operations. I need guidance on how to filter and search nested object data using the REST services. Currently, I can directly access customer information using their email, but I also need to search for customers based on their telephone numbers. Thank you for your response, and I look forward to hearing from you.

Re: How to get customer details by telephone Number Magento2 rest Api?

To search for customers based on their telephone number using the Magento 2 API, send a GET request to the appropriate endpoint with the following parameters:

  • Field: addresses.telephone
  • Value: The telephone number you want to search for
  • Condition Type: eq

Ensure you have the correct endpoint and permissions, or seek help from a Magento 2 expert if needed.

Re: How to get customer details by telephone Number Magento2 rest Api?

Hi @devcx9gmai328a 

  1. Authenticate and Get Access Token: First, you need to authenticate and obtain an access token to make authenticated API requests. You can refer to Magento 2 documentation on how to do this: https://developer.adobe.com/commerce/webapi/rest/authentication/

  2. Find Customer by Telephone Number: Once you have the access token, you can use the /V1/customers/search endpoint to search for customers by telephone number. You'll need to provide the telephone number in the request body.

    Here's an example of how you might structure the request:

POST /rest/V1/customers/search

Headers:
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json

Body:
{
"searchCriteria": {
"filterGroups": [
{
"filters": [
{
"field": "addresses.telephone",
"value": "CUSTOMER_PHONE_NUMBER",
"condition_type": "eq"
}
]
}
]
}
}