Order Processing with REST APIs Tutorial
Step 3. Create a customer
Customers can make purchases in three ways:
- As a logged-in user
- As a guest user who logs in or creates an account when the order is placed
- As a guest user who does not create an account
This tutorial creates an order by a logged-in user. Magento provides additional REST endpoints for handling guest users.
Create a customer account
Creating a customer account requires admin permissions.
This example shows a simplified way of creating a customer account. Typically, you would not define a customer password using plain text. Instead, you would specify the payload without the password
parameter. By default if the call is successful, Magento sends a “Welcome” email to the customer that includes a request to set the password. You could also initiate a password reset email by calling PUT /V1/customers/password
.
Endpoint
POST http://<host>/rest/default/V1/customers
Headers
Content-Type
application/json
Authorization
Bearer <admin token>
Payload
It is recommended that you substitute the value of the email
parameter with a real email address so that you receive all notifications.
Response
Magento assigned this user id
value of 2
.
You can log in to the Luma store using the user name jdoe@example.com
and password Password1
.
Get the customer’s access token
To get a customer’s access token, you must specify the customer’s username and password in the payload. You do not need to specify an admin authorization token.
By default, a customer token is valid for 1 hour. To change this value, log in to Admin and go to Configuration > Services > OAuth > Access Token Expiration.
Endpoint
POST http://<host>/rest/default/V1/integration/customer/token
Headers
Content-Type
application/json
Payload
Response
Magento returns the customer’s access token. This token must be specified in the authorization header of every call the customer makes on his or her own behalf.
q0u66k8h42yaevtchv09uyy3y9gaj2ap
Verify this step
- Log in to the Luma website using the email
jdoe@example.com
and passwordPassword1
. - Click the account name (Jane) in the upper right corner and select My Account.
- Click Address Book to view the default billing and shipping addresses.