create customer account Magento API

Magento 2 API How to create a customer

There are several ways for customers to make purchases, In this post, we will show you the easiest way to create a customer account using Magento 2 API. Follow our step by step guides to create a simple customer using Postman.

Step 1: Generate Access Token

First, to create a customer account, admin authorization is required. Complete the following steps to authorize access to resources:

In the POST request enter your store URL along with this endpoint.

POST <host>/rest/V1/integration/admin/token

Enter your Magento admin username and password in Body sections, then click Send

Postman endpoint request
{
  "username": "string",
  "password": "string"
}

Step 2: Create a Customer Account

Create a new request using this endpoint:

POST <host>/rest/<store_code>/V1/customers

In Authorization section:

  • Choose Type: Bearer Token
  • Then paste your token

Use the following code sample in the Body section to create your account. A real email address is recommended to receive all notifications.

{
  "customer": {
    "email": "julielawson@example.com",
    "firstname": "Julie",
    "lastname": "Lawson",
    "addresses": [
      {
        "defaultShipping": true,
        "defaultBilling": true,
        "firstname": "Julie",
        "lastname": "Lawson",
        "region": {
          "regionCode": "NV",
          "region": "Nevada",
          "regionId": 39
        },
        "postcode": "89406",
        "street": [
          "3703 Wescam Court"
        ],
        "city": "Fallon",
        "telephone": "860-212-5597",
        "countryId": "US"
      }
    ]
  },
  "password": "Password42"
}
customer API request

RESPONSE

Magento assigned this user id value of 35.

{
    "id": 35,
    "group_id": 1,
    "default_billing": "9",
    "default_shipping": "9",
    "created_at": "2020-09-28 07:57:39",
    "updated_at": "2020-09-28 07:57:40",
    "created_in": "Default Store View",
    "email": "julielawson@example.com",
    "firstname": "Julie",
    "lastname": "Lawson",
    "store_id": 1,
    "website_id": 1,
    "addresses": [
        {
            "id": 9,
            "customer_id": 35,
            "region": {
                "region_code": "NV",
                "region": "Nevada",
                "region_id": 39
            },
            "region_id": 39,
            "country_id": "US",
            "street": [
                "3703 Wescam Court"
            ],
            "telephone": "860-212-5597",
            "postcode": "89406",
            "city": "Fallon",
            "firstname": "Julie",
            "lastname": "Lawson",
            "default_shipping": true,
            "default_billing": true
        }
    ],
    "disable_auto_group_change": 0,
    "extension_attributes": {
        "is_subscribed": false
    }
}
customer API response

Step 3: Verify the Result

  1. Log in to your website using the email julielawson@example.com and password Password42.
  2. Click the account name (Julie) in the upper right corner then select My Account.
  3. Check the default billing and shipping addresses.
check account information

To conclude, I have shown you the complete steps to create a customer account using Magento 2 API. Learn more about Magento 2 REST API here. Also, should you have any questions let me know in the comment below.

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email