Drupal Commerce Login and register API

Here we are going to configure and use login and register Rest API’s. So for Drupal commerce we can use the Drupal Core Restful web service. Make  sure you have installed the Core Restful web service module and other related module as below.

Here Rest UI is a contributed module.

Go to Configuration -> Web services -> Rest

Enable below resources which are available in Core Restful web service module.

Make sure we are not using basic authentication for Register resource, always use cookie authentication, 

Customer Login API

Below provided request details for  customer login. Login API is in built to Drupal core,  so no need of any resource to be enabled.

Below provided the request details.

URL- http://your-domain/user/login?_format=json

Request Body:  {

  “name”: “admin”,

  “pass”: “admin123”


No need for Authentication header.

So you can see the response below for successful login.  Uid is the user id of the customer.

you can use logout_token for logging out the user as below get request

While using user logout API it gives a blank response with 204 status

it gives a blank response with 204 status.

Customer Register API

Here we are going to register an anonymous user using Rest API

Make sure the anonymous user role has below permission in People->Permissions

Call the API as provided below.

Request URL- http://yourdomain/user/register?_format=json

Method  POST

Request BodyBody Raw text

Get the session token from below which we need to use as a x-csrf token for anonymous user.

Get Request – http://localhost/dnstore/web/session/token?_format=json

No need of any headers, this will provide session token of anonymous user as a plain text, this we need to pass in headers as x-csrf-token as provided below in headers.


After submission you will receive response as below.

So here Login and register API’s provides basic details of the customer after successful login/register. We will be discussing in next article topics like how to get the users orders and how to view/update billing and shipping address of the customer.

Get Free E-book
Get a free Ebook on Drupal 8 -theme tutorial
I agree to have my personal information transfered to MailChimp ( more information )
if you like this article Buy me a Coffee this will be an ispiration for me to write articles like this.

You may also like...