Vueer
Vueer

Reputation: 1502

WooCommerce API: Passing email address in the right way

I try to fetch some data from the WooCommerce API with:

let currentUserEmail = "[email protected]"
let apiURL = 'https://www.url.com/wc-api/v3/customers/email/' + currentUserEmail;

or

let currentUserEmail = "[email protected]"
let apiURL = 'https://www.url.com/wc-api/v3/customers/email/' + encodeURIComponent(currentUserEmail);

In both for this email address case I get a 404 error. I think this is because of the + sign. How can I pass the email address correctly to send the get request in the right way?

Upvotes: 1

Views: 282

Answers (1)

Plub
Plub

Reputation: 83

Email is not it's own endpoint but instead a parameter of customers so you should do this instead

let currentUserEmail = "[email protected]"
let apiURL = 'https://www.url.com/wc-api/v3/customers?email=' + currentUserEmail;

You can find documentation of all parameters available here: https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-customers

Upvotes: 1

Related Questions