Create a customer subscribed to SMS marketing
Description
Create a customer and subscribe them to SMS marketing.
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"
}
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/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"
}
}
}
}'
Remix
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();
Ruby
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)
Node.js
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"
}
}
},
},
});
Response
{
"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"
}
}
}
}
Create a customer without required attributes
Description
Creating a customer without an email, phone, first name or last name fails and returns an error.
Query
mutation customerCreate($input: CustomerInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
email
phone
taxExempt
emailMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
}
addresses {
address1
city
countryCode
phone
zip
}
}
}
}
Variables
{
"input": {
"email": null,
"phone": null,
"firstName": null,
"lastName": null
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/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 emailMarketingConsent { marketingState marketingOptInLevel consentUpdatedAt } firstName lastName amountSpent { amount currencyCode } smsMarketingConsent { marketingState marketingOptInLevel } addresses { address1 city countryCode phone zip } } } }",
"variables": {
"input": {
"email": null,
"phone": null,
"firstName": null,
"lastName": null
}
}
}'
Remix
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
emailMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
}
addresses {
address1
city
countryCode
phone
zip
}
}
}
}`,
{
variables: {
"input": {
"email": null,
"phone": null,
"firstName": null,
"lastName": null
}
},
},
);
const data = await response.json();
Ruby
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
emailMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
}
addresses {
address1
city
countryCode
phone
zip
}
}
}
}
QUERY
variables = {
"input": {
"email": null,
"phone": null,
"firstName": null,
"lastName": null
}
}
response = client.query(query: query, variables: variables)
Node.js
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
emailMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
}
addresses {
address1
city
countryCode
phone
zip
}
}
}
}`,
"variables": {
"input": {
"email": null,
"phone": null,
"firstName": null,
"lastName": null
}
},
},
});
Response
{
"customerCreate": {
"userErrors": [
{
"field": null,
"message": "Customer must have a name, phone number or email address"
}
],
"customer": null
}
}
Create a new metafield on a new customer
Description
Create a new metafield `my_field.nickname` on a new
customer.
Alternatively, refer to the
[metafieldsSet](https://shopify.dev/api/admin-graphql/latest/mutations/metafieldsset) mutation
to create and/or update metafields on customer resources.
Query
mutation createCustomerMetafields($input: CustomerInput!) {
customerCreate(input: $input) {
customer {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
Variables
{
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "nickname",
"type": "single_line_text_field",
"value": "rob"
}
],
"email": "bob.norman@example.com"
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation createCustomerMetafields($input: CustomerInput!) { customerCreate(input: $input) { customer { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }",
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "nickname",
"type": "single_line_text_field",
"value": "rob"
}
],
"email": "bob.norman@example.com"
}
}
}'
Remix
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createCustomerMetafields($input: CustomerInput!) {
customerCreate(input: $input) {
customer {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
{
variables: {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "nickname",
"type": "single_line_text_field",
"value": "rob"
}
],
"email": "bob.norman@example.com"
}
},
},
);
const data = await response.json();
Ruby
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 createCustomerMetafields($input: CustomerInput!) {
customerCreate(input: $input) {
customer {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
QUERY
variables = {
"input": {
"metafields": [{"namespace"=>"my_field", "key"=>"nickname", "type"=>"single_line_text_field", "value"=>"rob"}],
"email": "bob.norman@example.com"
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createCustomerMetafields($input: CustomerInput!) {
customerCreate(input: $input) {
customer {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "nickname",
"type": "single_line_text_field",
"value": "rob"
}
],
"email": "bob.norman@example.com"
}
},
},
});
Response
{
"customerCreate": {
"customer": {
"id": "gid://shopify/Customer/1073340085",
"metafields": {
"edges": [
{
"node": {
"id": "gid://shopify/Metafield/1069230109",
"namespace": "my_field",
"key": "nickname",
"value": "rob"
}
}
]
}
},
"userErrors": []
}
}
Creates a customer
Description
Create a customer with an address.
Query
mutation customerCreate($input: CustomerInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
email
phone
taxExempt
emailMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
}
addresses {
address1
city
country
phone
zip
}
}
}
}
Variables
{
"input": {
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"firstName": "Steve",
"lastName": "Lastname",
"emailMarketingConsent": {
"marketingOptInLevel": "CONFIRMED_OPT_IN",
"marketingState": "SUBSCRIBED"
},
"addresses": [
{
"address1": "412 fake st",
"city": "Ottawa",
"province": "ON",
"phone": "+16469999999",
"zip": "A1A 4A1",
"lastName": "Lastname",
"firstName": "Steve",
"countryCode": "CA"
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/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 emailMarketingConsent { marketingState marketingOptInLevel consentUpdatedAt } firstName lastName amountSpent { amount currencyCode } smsMarketingConsent { marketingState marketingOptInLevel } addresses { address1 city country phone zip } } } }",
"variables": {
"input": {
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"firstName": "Steve",
"lastName": "Lastname",
"emailMarketingConsent": {
"marketingOptInLevel": "CONFIRMED_OPT_IN",
"marketingState": "SUBSCRIBED"
},
"addresses": [
{
"address1": "412 fake st",
"city": "Ottawa",
"province": "ON",
"phone": "+16469999999",
"zip": "A1A 4A1",
"lastName": "Lastname",
"firstName": "Steve",
"countryCode": "CA"
}
]
}
}
}'
Remix
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
emailMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
}
addresses {
address1
city
country
phone
zip
}
}
}
}`,
{
variables: {
"input": {
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"firstName": "Steve",
"lastName": "Lastname",
"emailMarketingConsent": {
"marketingOptInLevel": "CONFIRMED_OPT_IN",
"marketingState": "SUBSCRIBED"
},
"addresses": [
{
"address1": "412 fake st",
"city": "Ottawa",
"province": "ON",
"phone": "+16469999999",
"zip": "A1A 4A1",
"lastName": "Lastname",
"firstName": "Steve",
"countryCode": "CA"
}
]
}
},
},
);
const data = await response.json();
Ruby
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
emailMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
}
addresses {
address1
city
country
phone
zip
}
}
}
}
QUERY
variables = {
"input": {
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"firstName": "Steve",
"lastName": "Lastname",
"emailMarketingConsent": {
"marketingOptInLevel": "CONFIRMED_OPT_IN",
"marketingState": "SUBSCRIBED"
},
"addresses": [{"address1"=>"412 fake st", "city"=>"Ottawa", "province"=>"ON", "phone"=>"+16469999999", "zip"=>"A1A 4A1", "lastName"=>"Lastname", "firstName"=>"Steve", "countryCode"=>"CA"}]
}
}
response = client.query(query: query, variables: variables)
Node.js
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
emailMarketingConsent {
marketingState
marketingOptInLevel
consentUpdatedAt
}
firstName
lastName
amountSpent {
amount
currencyCode
}
smsMarketingConsent {
marketingState
marketingOptInLevel
}
addresses {
address1
city
country
phone
zip
}
}
}
}`,
"variables": {
"input": {
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"firstName": "Steve",
"lastName": "Lastname",
"emailMarketingConsent": {
"marketingOptInLevel": "CONFIRMED_OPT_IN",
"marketingState": "SUBSCRIBED"
},
"addresses": [
{
"address1": "412 fake st",
"city": "Ottawa",
"province": "ON",
"phone": "+16469999999",
"zip": "A1A 4A1",
"lastName": "Lastname",
"firstName": "Steve",
"countryCode": "CA"
}
]
}
},
},
});
Response
{
"customerCreate": {
"userErrors": [],
"customer": {
"id": "gid://shopify/Customer/1073340090",
"email": "steve.lastnameson@example.com",
"phone": "+16465555555",
"taxExempt": false,
"emailMarketingConsent": {
"marketingState": "SUBSCRIBED",
"marketingOptInLevel": "CONFIRMED_OPT_IN",
"consentUpdatedAt": "2024-11-05T14:29:06Z"
},
"firstName": "Steve",
"lastName": "Lastname",
"amountSpent": {
"amount": "0.0",
"currencyCode": "USD"
},
"smsMarketingConsent": {
"marketingState": "NOT_SUBSCRIBED",
"marketingOptInLevel": "SINGLE_OPT_IN"
},
"addresses": [
{
"address1": "412 fake st",
"city": "Ottawa",
"country": "Canada",
"phone": "+16469999999",
"zip": "A1A 4A1"
}
]
}
}
}