Requires write_customers access scope. Also: User needs customers permission.

Create a new customer. As of API version 2022-10, apps using protected customer data must meet the protected customer data requirements.


The input fields to create a customer.


Was this section helpful?

The created customer.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation createCustomerMetafields($input: CustomerInput!) {
  customerCreate(input: $input) {
    customer {
      id
      metafields(first: 3) {
        edges {
          node {
            id
            namespace
            key
            value
          }
        }
      }
    }
    userErrors {
      message
      field
    }
  }
}
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"
    }
  }
}'
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();
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)
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"
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$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]);
Hide code
Input variables
Copy
{
  "input": {
    "metafields": [
      {
        "namespace": "my_field",
        "key": "nickname",
        "type": "single_line_text_field",
        "value": "rob"
      }
    ],
    "email": "bob.norman@example.com"
  }
}
Hide code
Response
JSON
{
  "customerCreate": {
    "customer": {
      "id": "gid://shopify/Customer/1073339463",
      "metafields": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/Metafield/1069229089",
              "namespace": "my_field",
              "key": "nickname",
              "value": "rob"
            }
          }
        ]
      }
    },
    "userErrors": []
  }
}