Anchor to customerCreatecustomer
customerCreate
mutation
Requires access scope.
Create a new customer. As of API version 2022-10, apps using protected customer data must meet the protected customer data requirements.
Anchor to Arguments
Arguments
- Anchor to inputinput•Customer
Input! required The input fields to create a customer.
Was this section helpful?
Anchor to CustomerCreatePayload returnsCustomerCreatePayload returns
- Anchor to customercustomer•
The created customer.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a customer subscribed to SMS marketing
- Create a customer without required attributes
- Create a new metafield on a new customer
- Creates a customer
- customerCreate reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation customerCreate($input: CustomerInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
email
phone
taxExempt
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
}
}
}`,
{
variables: {
"input": {
mutation customerCreate($input: CustomerInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
email
phone
taxExempt
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation customerCreate($input: CustomerInput!) { customerCreate(input: $input) { userErrors { field message } customer { id email phone taxExempt firstName lastName amountSpent { amount currencyCode } smsMarketingConsent { marketingState marketingOptInLevel consentUpdatedAt } } } }",
"variables": {
"input": {
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"firstName": "Steve",
"smsMarketingConsent": {
"marketingState": "SUBSCRIBED",
"marketingOptInLevel": "SINGLE_OPT_IN"
}
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation customerCreate($input: CustomerInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
email
phone
taxExempt
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
}
}
}`,
{
variables: {
"input": {
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"firstName": "Steve",
"smsMarketingConsent": {
"marketingState": "SUBSCRIBED",
"marketingOptInLevel": "SINGLE_OPT_IN"
}
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation customerCreate($input: CustomerInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
email
phone
taxExempt
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
}
}
}`,
"variables": {
"input": {
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"firstName": "Steve",
"smsMarketingConsent": {
"marketingState": "SUBSCRIBED",
"marketingOptInLevel": "SINGLE_OPT_IN"
}
}
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation customerCreate($input: CustomerInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
email
phone
taxExempt
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
}
}
}
QUERY
variables = {
"input": {
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"firstName": "Steve",
"smsMarketingConsent": {
"marketingState": "SUBSCRIBED",
"marketingOptInLevel": "SINGLE_OPT_IN"
}
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"input": {
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"firstName": "Steve",
"smsMarketingConsent": {
"marketingState": "SUBSCRIBED",
"marketingOptInLevel": "SINGLE_OPT_IN"
}
}
}
Response
JSON{
"customerCreate": {
"userErrors": [],
"customer": {
"id": "gid://shopify/Customer/1073340122",
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"taxExempt": false,
"firstName": "Steve",
"lastName": null,
"amountSpent": {
"amount": "0.0",
"currencyCode": "USD"
},
"smsMarketingConsent": {
"marketingState": "SUBSCRIBED",
"marketingOptInLevel": "SINGLE_OPT_IN",
"consentUpdatedAt": "2024-11-05T14:29:24Z"
}
}
}
}