In this blog we will get customer data by customer id using REST API.

First we need to admin token to get customer info.
We can refer blog for generate admin token
https://www.magedad.com/magento-2-how-to-generate-admin-token-using-rest-api/

Rest API endpoint = https://domain.test/rest/V1/customers/:customerId
Rest API endpoint for store(default is store code) = https://domain.test/rest/default/V1/customers/:customerId
Method = GET
Content type = Content-Type:application/json
Header = Authorization: Bearer xxxx_admin_token_xxxx

Examples:
The following image shows a get customer using customer id by a REST client:

Magento2 How to get customer data using customer id by REST API?


Here is simple php code for call API. This code is not recommended for Magento.

PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://domain.test/rest/V1/customers/89', # customer id = 89
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer xxxx_admin_token_xxxx'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;


I hope this blog is useful to get customer data using customer id by REST API. In case, I missed anything or need to add some more information, Don’t heisted to leave a comment in this blog, I’ll get back with some positive approach.

Keep liking 👍 Keep sharing 📣 Keep loving ❤️ Keep inspiring 🤩

Write A Comment