Magento 2 API – Create New Customer
End-to-end Magento integration
Integrate any app or service. Consult our API development experts.
Hello, Magento peeps!
My last blog post was all about using SearchCriteria through Magento 2 API. In case you missed reading it, check it out at Magento 2 API – SearchCriteria. This blog post is all about how to create a new customer in Magento 2 using rest API.
It is important for the online stores to facilitate the customers to create an account on their store for saving details such as personal information, address, payment methods, etc. They can be re-used for future purchases, making the shopping experience more smooth and convenient. If you are developing a third-party app or mobile app on Magento, you may want to allow the customers to create accounts on your store. In such a case, you can use the create account API by Magento 2.
The Magento 2 API allows the guest users to create account in the store by passing the required fields such as name, email, address, etc. Here’s the complete tutorial to Magento 2 API – Create New Customer. You can use this API for customer registration in Magento 2.
Let’s begin!
How to Create New Customer Using Magento 2 API?
In order to create a new customer in Magento 2 using API, we’ll be using the POST method to send the customer’s details, such as first name, last name, email, address, etc., to the store_url/rest/V1/customers path. The request will create a new customer account in the store with the sent details through the API, and the customer will be able to log in using the credentials. You can refer to the details provided below for a better understanding.
Method: POST
URL: store_url/rest/V1/customers
Body:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
{ "customer": { "firstname": "John", "lastname": "Deo", "addresses": [ { "defaultShipping": true, "defaultBilling": true, "firstname": "John", "lastname": "Deo", "region": { "regionCode": "GJ", "region": "Gujarat", "regionId": 588 }, "postcode": "364001", "street": [ "Shiv Elite" ], "city": "Bhavnagar", "telephone": "7206997997", "countryId": "IN" } ] }, "password": "Meet@123" } |
Response:
On successful creation of the customer account in Magento 2, the API response returns the details of the custom eraccount with information such as id, email, name, address, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
{ "id": 7, "group_id": 1, "default_billing": "3", "default_shipping": "3", "created_at": "2022-05-13 11:08:13", "updated_at": "2022-05-13 11:08:13", "created_in": "Default Store View", "firstname": "John", "lastname": "Deo", "store_id": 1, "website_id": 1, "addresses": [ { "id": 3, "customer_id": 7, "region": { "region_code": "CA", "region": "California", "region_id": 12 }, "region_id": 12, "country_id": "US", "street": [ "Shiv Elite" ], "telephone": "7206997997", "postcode": "364001", "city": "Bhavnagar", "firstname": "John", "lastname": "Deo", "default_shipping": true, "default_billing": true } ], "disable_auto_group_change": 0, "extension_attributes": { "is_subscribed": false } } |
Conclusion
The create a new account functionality is really important for the online stores to remember customers’ information and provide a smoother shopping experience. I provided complete details about the Magento 2 API that you can use to add create a new account functionality to your third-party development on Magento 2. In case you have any queries regarding the provided solution, feel free to comment. I would be happy to help you. 😇
Also, do not forget to share this API guide with your Magento 2 friends via social media. 😊
Thanks for reading! 🍀
◄ Magento 2 API – Get All Available CurrenciesMagento 2 API – Get Customer Token ►
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How to Setup & Use Microsoft Clarity on Your Website [2024]
Magento 2 API – Get Customer Token
Next