Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Endpoint for user login/signup in Woocommerce Rest API v2

I have searched completely in Woocommerce REST API documentation for the endpoint of user login/signup but unable to find it. Can anyone provide me the link to the endpoint and its documentation?

like image 217
user1534536 Avatar asked Jul 12 '15 06:07

user1534536


3 Answers

You can achieve this in lot of ways.

1st method is:

It's not specific for WooCommerce but also for all WordPress login and sign up


For sign up:

Method POST

Params : username,email,password

https://example.com/wp-json/wp/v2/users

It will create a new user


For login:

Method POST

Params : username/email,password

https://example.com/wp-json/jwt-auth/v1/token

It will generate an access token which you can pass in for your future requests.

You can use JWT Authentication for WP REST API for login purposes

like image 72
Rajilesh Panoli Avatar answered Oct 23 '22 12:10

Rajilesh Panoli


For reference: Woocommerce users or customers are actually Wordpress users, more like blog subscribers (just like woocommere products are wordpress posts, so to create a user you could use WP_API functions for that purpose.

wp_create_user To create users with minimum parameters (username, password and email).
wp_insert_user To create users with extended user data.

I assume that user roles must match those that woocommerce handle (customers or shop managers) Now there's also an endpoint for creating/updating/listing customers in WooCommerce REST API (http://woothemes.github.io/woocommerce-rest-api-docs/#customers) but there's no login/auth support at the moment.

For login/authenthication there's two mechanisms in the WP_API: CookieAuth and OAuth If you explain what you are trying to accomplish it would be easier to help.

like image 45
Anfelipe Avatar answered Oct 23 '22 13:10

Anfelipe


You can create / signup user by hitting customers/ endpoint with params : username , email and password.

later you can insert more details like shipping or billing address by hitting customers/<userid>

Now, There's no endpoint available in the REST API for login customers but,

You can achieve this by:
  • installing JWT Authentication for WP REST API plugin in your WordPress admin.
  • after installing this plugin, now you have the endpoint for login a customer

https://yourdomain.com/wp-json/jwt-auth/v1/token?password=123456789&username=nicename

NOTE: it is recommended to use a username instead of email for login a customer because WordPress authenticates the user by the username.

  • here's the last step: Don't forget to add define('JWT_AUTH_SECRET_KEY', 'your-top-secrect-key'); in your wp-config.php file.
like image 1
M.Daniyal Aslam Avatar answered Oct 23 '22 12:10

M.Daniyal Aslam