In this article, we will be looking into how we can create a new customer in Magento 2 using its API.
We will be passing the admin bearer token to authenticate the APIs.
Create New Customer
API Doc:
https://adobe-commerce.redoc.ly/2.4.5-admin/tag/customers
Endpoint:
GET <host>/rest/V1/customers
Authentication Bearer Token:
<admin-token>
Payload:
{
"customer": {
"firstname": "Test",
"lastname": "Example",
"email": "test@example.com"
},
"password": "Test1234"
}
Response:
{
"id": 2,
"group_id": 1,
"created_at": "2022-12-30 04:30:07",
"updated_at": "2022-12-30 04:30:07",
"created_in": "Default Store View",
"email": "test@example.com",
"firstname": "Test",
"lastname": "Example",
"store_id": 1,
"website_id": 1,
"addresses": [],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
}
}
Create Customer using cURL Request
curl --location --request POST 'https://app.your-project.test/rest/V1/customers' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJraWQiOiIxIiwiYWxnIjoiSFMyNxxxxx' \
--data-raw '{
"customer": {
"firstname": "Test",
"lastname": "Example",
"email": "test@example.com"
},
"password": "Test1234"
}'
Hope this helps. Thanks.
Magento REST API Reference: https://developer.adobe.com/commerce/webapi/rest/quick-reference/