Falan Abdulla
Falan Abdulla

Reputation: 1

Can't get WooCommerce customers by email

When I make an API call to get users by mail address, I get the error:

"{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}"

All other calls like /products/ or /orders/ work without problem. Pretty Links in permalink settings are activated.

this.WooCommerce = WC({
  url: 'http://............./', 
  consumerKey: 'ck_xxxxxxxxxx', 
  consumerSecret: 'cs_xxxxxxxxxxxxxx', 
  wpAPI: true, 
  queryStringAuth: true,
  verifySsl: true,
  version: 'wc/v2' 

checkEmail(){

let validEmail = false;

let reg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

if(reg.test(this.newUser.email)){
  //email looks valid

  this.wooCommerce.getAsync("customers/email/"+ this.newUser.email).then( (data) => {
    console.log(data);

Upvotes: 0

Views: 1084

Answers (1)

Mohan Kumar
Mohan Kumar

Reputation: 36

this.wooCommerce.getAsync("customers/email/"+ this.newUser.email).then( (data) => {
    console.log(data);
}

change this to====>>>

this.wooCommerce.getAsync("customers?email="+ this.newUser.email).then( (data) => {
    console.log(data);
}

Upvotes: 2

Related Questions