createCustomerV2 mutation
The createCustomerV2 mutation creates a customer account. Use the createCustomerAddress mutation to complete the customer profile and define billing and shipping addresses.
The createCustomerV2 mutation supersedes the createCustomer mutation as the means to create a customer account. The input objects differ between these two mutations. The createCustomer mutation required the CustomerInput object, as did the updateCustomer mutation. The attributes required for creating a customer are different than those for updating a customer, but you could not determine this by looking at the schema. The createCustomerV2 mutation requires the CustomerCreateInput object, which it does not share with the updateCustomerV2 mutation.
In keeping with current security and privacy best practices, if you include the date_of_birth input attribute, be sure you are aware of any potential legal and security risks associated with the storage of customers' full date of birth (month, day, year) along with other personal identifiers, such as full name, before collecting or processing such data.
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.
Syntax
mutation: {createCustomerV2(input: CustomerCreateInput!) {CustomerOutput}}
Reference
The createCustomerV2 reference provides detailed information about the types and fields defined in this mutation.
Example usage
The following examples demonstrate the createCustomerV2 mutation.
Create a customer
The following call creates a new customer.
Request:
mutation {
createCustomerV2(
input: {
firstname: "Bob"
lastname: "Loblaw"
email: "bobloblaw@example.com"
password: "b0bl0bl@w"
is_subscribed: true
}
) {
customer {
firstname
lastname
email
is_subscribed
}
}
}
Response:
{
"data": {
"createCustomerV2": {
"customer": {
"firstname": "Bob",
"lastname": "Loblaw",
"email": "bobloblaw@example.com",
"is_subscribed": true
}
}
}
}
Create a customer with custom attributes
The following call creates a new customer, assigning values for custom attributes.
The merchant has previously created the custom attributes alternative_email and studies for customers.
Request:
mutation {
createCustomerV2(
input: {
firstname: "Bob"
lastname: "Loblaw"
email: "bobloblaw@example.com"
password: "b0bl0bl@w"
is_subscribed: true
custom_attributes: [
{
attribute_code: "alternative_email"
value: "abc@example.com"
},
{
attribute_code: "studies"
value: "501,502"
selected_options: [
{
uid: "NTEw"
value: "501"
},
{
uid: "NTEx"
value: "502"
}
]
}
]
}
) {
customer {
firstname
lastname
email
is_subscribed
custom_attributes {
code
... on AttributeValue {
value
}
... on AttributeSelectedOptions {
selected_options {
label
value
}
}
}
}
}
}
Response:
{
"data": {
"createCustomer": {
"customer": {
"firstname": "Bob",
"lastname": "Loblaw",
"email": "bobloblaw@example.com",
"is_subscribed": true,
"custom_attributes": [
{
"code": "alternative_email",
"value": "abc@example.com"
},
{
"code": "studies",
"selected_options": [
{
"label": "BSc",
"value": "501"
},
{
"label": "MBA",
"value": "502"
}
]
}
]
}
}
}
}
Input attributes
The following table lists the attributes you can use as input for the createCustomerV2 mutation.
allow_remote_shopping_assistancedate_of_birthcustom_attributesdobdate_of_birth instead. The customer's date of birthemailfirstnamegenderis_subscribedlastnamemiddlenamepasswordprefixsuffixtaxvatThe AttributeValueInput object contains the following attributes:
attribute_codeselected_optionsvalueThe AttributeInputSelectedOption specifies selected option for dropdown or multiselect attribute value. This object contains the following attributes:
valueErrors
A customer with the same email address already exists in an associated website.input.email argument belongs to an existing customer."Email" is not a valid email address.input.email argument has an invalid format.Field CustomerInput.email of required type String! was not providedinput.email argument was omitted.Field "xxx" is not defined by type CustomerInput.input.xxx argument is undefined.Required parameters are missing: First Nameinput.firstname argument was omitted or contains an empty value.