Creating a customer account is one of the most essential operations in any eCommerce store. Magento 2 supports this via REST and GraphQL APIs. In this blog, we’ll explore how to create a customer account using GraphQL in Magento 2 with examples, query structure, and best practices.
Whether you’re a developer integrating a mobile app or building a headless frontend with React or Vue, this guide will help you get started.
Why Use GraphQL for Customer Operations?
Magento 2 introduced full GraphQL support for storefront operations, which allows frontend developers to:
- Request only the data needed
- Improve performance with fewer API calls
- Simplify integration for mobile apps and PWA Studio
Creating a customer account via GraphQL is clean, efficient, and fast.
Prerequisites
Before we dive into the query, make sure:
- Your Magento 2 store is version 2.3.3 or above (GraphQL stable)
- GraphQL module is enabled
- A GraphQL client like Altair, Postman, or Magento PWA Studio is ready
- Magento base URL is accessible, typically like:
https://yourstore.com/graphql
GraphQL Mutation to Create a Customer Account
Magento provides a mutation called createCustomer
to register new accounts.
mutation {
createCustomer(
input: {
firstname: "John"
lastname: "Doe"
email: "john.doe@example.com"
password: "StrongPassword123"
}
) {
customer {
id
firstname
lastname
email
}
}
}
The field Mutation.createCustomer is deprecated. Use `createCustomerV2` instead.
In this blog, We will use createCustomerV2 mutation.
Request
mutation {
createCustomerV2(
input: {
firstname: "Jigar"
lastname: "Karangiya"
email: "jigarkarangiyablogs@gmail.com"
password: "b0bl0bl@w"
is_subscribed: true
}
) {
customer {
firstname
lastname
email
is_subscribed
}
}
}
Response
{
"data": {
"createCustomer": {
"customer": {
"firstname": "Jigar",
"lastname": "Karangiya",
"email": "jigarkarangiyablogs@gmail.com",
"is_subscribed": true,
}
}
}
}
As of version 2.4.7, you can use the custom_attributes
field to define an array of custom attributes to apply to the customer.
Create customer account with custom attributes
Request
mutation {
createCustomerV2(
input: {
firstname: "Jigar"
lastname: "Karangiya"
email: "jigar.karangiya@test.com"
password: "sjjsjs@444js#"
is_subscribed: true
custom_attributes: [
{
attribute_code: "alternative_email"
value: "jigar.karangiya@2ndemail.com"
},
{
attribute_code: "certificates"
value: "992,995"
selected_options: [
{
uid: "Adobe Commerce - Certified Professional Developer"
value: "992"
},
{
uid: "Adobe Commerce - Certified Expert Developer"
value: "995"
}
]
}
]
}
) {
customer {
firstname
lastname
email
is_subscribed
custom_attributes {
code
... on AttributeValue {
value
}
... on AttributeSelectedOptions {
selected_options {
label
value
}
}
}
}
}
}
Response
{
"data": {
"createCustomer": {
"customer": {
"firstname": "Jigar",
"lastname": "Karangiya",
"email": "jigar.karangiya@test.com",
"is_subscribed": true,
"custom_attributes": [
{
"code": "alternative_email",
"value": "jigar.karangiya@2ndemail.com"
},
{
"code": "certificates",
"selected_options": [
{
"label": "Adobe Commerce - Certified Professional Developer",
"value": "992"
},
{
"label": "Adobe Commerce - Certified Expert Developer",
"value": "995"
}
]
}
]
}
}
}
}
Input attributes
You can use the following attributes as input for the createCustomerV2
mutation.
Field Name | Description |
---|---|
allow_remote_shopping_assistance – Boolean | Indicates whether the customer has enabled remote shopping assistance. |
custom_attributes – [AttributeValueInput] | The customer’s custom attributes. |
date_of_birth – String | The customer’s date of birth. |
dob – String | |
email – String! | The customer’s email address. |
firstname – String! | The customer’s first name. |
gender – Int | The customer’s gender (Male – 1, Female – 2). |
is_subscribed – Boolean | Indicates whether the customer is subscribed to the company’s newsletter. |
lastname – String! | The customer’s family name. |
middlename – String | The customer’s middle name. |
password – String | The customer’s password. |
prefix – String | An honorific, such as Dr., Mr., or Mrs. |
suffix – String | A value such as Sr., Jr., or III. |
taxvat – String | The customer’s Tax/VAT number (for corporate customers). |
Common Response Errors
Error | Description |
---|---|
A customer with the same email address already exists in an associated website. | The email provided in the input .email argument belongs to an existing customer. |
"Email" is not a valid email address. | The value provided in the input .email argument has an invalid format. |
Field CustomerInput.email of required type String! was not provided | The input .email argument was omitted. |
Field "xxx" is not defined by type CustomerInput. | The input .xxx argument is undefined. |
Required parameters are missing: First Name | The input .firstname argument was omitted or contains an empty value. |
Creating a customer account via Magento 2 GraphQL is straightforward, clean, and ideal for headless and modern frontend setups. With the power of GraphQL, developers can craft highly optimized experiences while keeping control of what data is sent or received.
You may also like,
Leave a Comment