Title: Get customers using REST API
Last modified: July 24, 2023

---

# Get customers using REST API

 *  Resolved [guardiano78](https://wordpress.org/support/users/guardiano78/)
 * (@guardiano78)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/get-customers-using-rest-api/)
 * Hello,
 * this is the first time I trying to use Woocommerce REST API.
   I’m reading the 
   documentation.
 * By using the following code, I’m able to get all customers:
 *     ```wp-block-code
       <?php
   
       $api_url_users = 'https://mywebsite.com/wp-json/wc/v3/customers';
       $api_key = "xxxxxx";
       $api_secret = "xxxxxx";
   
       // params
       $params = array(
           'per_page' => 100,
           'role' => 'all',
       );
   
       // header
       $headers = array(
           'Authorization: Basic ' . base64_encode($api_key . ':' . $api_secret)
       );
   
       $url = $api_url_customers . '?' . http_build_query($params);
   
   
       // cURL options
       $curl = curl_init();
       curl_setopt_array($curl, array(
           CURLOPT_URL => $url,
           CURLOPT_RETURNTRANSFER => true,
           CURLOPT_HTTPHEADER => $headers,
           CURLOPT_SSL_VERIFYPEER => true, 
       ));
   
       // response
       $response = curl_exec($curl);
       curl_close($curl);
   
   
       // JSON decode
       $customers = json_decode($response, true);
       ```
   
 * It works! … but now I need to get all customers that has a specific meta_key 
   empty. For example, if I need to get only customers that has postcode empty, 
   in your opinion, is it possible?
   I tried with something like that, but it doesn’t
   work:
 *     ```wp-block-code
       $params = array(
           'per_page' => 100,
           'role' => 'all',
           'meta_query' => array(
               array(
                   'key' => 'postcode',
                   'value' => '',
               ),
           ),
       );
       ```
   
 * Maybe “search” param it can help me, but I can’t found any example for how to
   use search in REST API. I don’t know, maybe i had some confusion. Anyone can 
   help me?
 * Thank you all.
    -  This topic was modified 2 years, 10 months ago by [guardiano78](https://wordpress.org/support/users/guardiano78/).

Viewing 1 replies (of 1 total)

 *  Plugin Support [Shameem – a11n](https://wordpress.org/support/users/shameemreza/)
 * (@shameemreza)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/get-customers-using-rest-api/#post-16932832)
 * Hi [@guardiano78](https://wordpress.org/support/users/guardiano78/)
 * Unfortunately, the WooCommerce REST API does not directly support querying customers
   by meta fields, like ‘postcode’. The ‘meta_query’ parameter you’ve used is not
   officially supported in WooCommerce REST API.
 * However, you can achieve this by creating a custom endpoint in your WordPress
   plugin or theme’s functions.php file. This custom endpoint will use `WP_User_Query`,
   which does support `meta_query`, to fetch the users.
 * Unfortunately, [custom coding](https://woocommerce.com/support-policy/) is not
   something we can assist with directly. However, I’ll keep this thread open for
   a bit to see if anyone from the community can lend a hand.
 * If you have any further questions on development or custom coding, don’t hesitate
   to reach out to some of our great resources available for support. Our WooCommerce
   community is brimming with skilled open-source developers who are active on the
   following channels:
    - [WooCommerce Developer Resources Portal](https://developer.woocommerce.com/)
    - [WooCommerce Advanced Facebook group](https://www.facebook.com/groups/advanced.woocommerce/)
    - [WooCommerce Developer Slack Channel](https://woocommerce.com/community-slack/)
    - Hire a [WooCommerce Expert](https://woocommerce.com/experts/)
 * As for the ‘search’ parameter, it only searches for the given string in the customer’s
   id, email, and username. It does not search in the user meta fields.
 * I hope this helps! Let us know if you have any other questions.
 * Thanks!

Viewing 1 replies (of 1 total)

The topic ‘Get customers using REST API’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shameem – a11n](https://wordpress.org/support/users/shameemreza/)
 * Last activity: [2 years, 10 months ago](https://wordpress.org/support/topic/get-customers-using-rest-api/#post-16932832)
 * Status: resolved