customer Createmutation
mutation
2024-10latest
Requires write
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.
Arguments
The input fields to create a customer.
Was this section helpful?
CustomerCreatePayload returns
The created customer.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Code examples for MUTATION: customerCreate
Query Reference for MUTATION: customerCreate
"mutation customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n customer {\n # Customer fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: customerCreate
"{\n \"input\": {\n \"addresses\": [\n {\n \"address1\": \"<your-address1>\",\n \"address2\": \"<your-address2>\",\n \"city\": \"<your-city>\",\n \"company\": \"<your-company>\",\n \"country\": \"<your-country>\",\n \"countryCode\": \"AC\",\n \"firstName\": \"<your-firstName>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"lastName\": \"<your-lastName>\",\n \"phone\": \"<your-phone>\",\n \"province\": \"<your-province>\",\n \"provinceCode\": \"<your-provinceCode>\",\n \"zip\": \"<your-zip>\"\n }\n ],\n \"email\": \"<your-email>\",\n \"emailMarketingConsent\": {\n \"consentUpdatedAt\": \"2019-09-07T15:50:00Z\",\n \"marketingOptInLevel\": \"CONFIRMED_OPT_IN\",\n \"marketingState\": \"INVALID\"\n },\n \"firstName\": \"<your-firstName>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"lastName\": \"<your-lastName>\",\n \"locale\": \"<your-locale>\",\n \"metafields\": [\n {\n \"description\": \"<your-description>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"key\": \"<your-key>\",\n \"namespace\": \"<your-namespace>\",\n \"type\": \"<your-type>\",\n \"value\": \"<your-value>\"\n }\n ],\n \"note\": \"<your-note>\",\n \"phone\": \"<your-phone>\",\n \"smsMarketingConsent\": {\n \"consentUpdatedAt\": \"2019-09-07T15:50:00Z\",\n \"marketingOptInLevel\": \"CONFIRMED_OPT_IN\",\n \"marketingState\": \"NOT_SUBSCRIBED\"\n },\n \"tags\": [\n \"<your-tags>\"\n ],\n \"taxExempt\": true,\n \"taxExemptions\": [\n \"CA_BC_COMMERCIAL_FISHERY_EXEMPTION\"\n ]\n }\n}"
Schema Reference for MUTATION: customerCreate
"input CustomerInput {\n addresses: [MailingAddressInput!]\n email: String\n emailMarketingConsent: CustomerEmailMarketingConsentInput\n firstName: String\n id: ID\n lastName: String\n locale: String\n metafields: [MetafieldInput!]\n note: String\n phone: String\n privateMetafields: [PrivateMetafieldInput!]\n smsMarketingConsent: CustomerSmsMarketingConsentInput\n tags: [String!]\n taxExempt: Boolean\n taxExemptions: [TaxExemption!]\n}\n\ninput MailingAddressInput {\n address1: String\n address2: String\n city: String\n company: String\n country: String\n countryCode: CountryCode\n firstName: String\n id: ID\n lastName: String\n phone: String\n province: String\n provinceCode: String\n zip: String\n}\n\ninput CustomerEmailMarketingConsentInput {\n consentUpdatedAt: DateTime\n marketingOptInLevel: CustomerMarketingOptInLevel\n marketingState: CustomerEmailMarketingState!\n}\n\ninput MetafieldInput {\n description: String\n id: ID\n key: String\n namespace: String\n type: String\n value: String\n}\n\ninput PrivateMetafieldInput {\n key: String!\n namespace: String!\n owner: ID\n valueInput: PrivateMetafieldValueInput!\n}\n\ninput CustomerSmsMarketingConsentInput {\n consentUpdatedAt: DateTime\n marketingOptInLevel: CustomerMarketingOptInLevel\n marketingState: CustomerSmsMarketingState!\n}\n"
Display Examples for MUTATION: customerCreate
[ { "example": { "type_name": "customercreate", "title": "Create a new metafield on a new customer", "description": "Create a new metafield `my_field.nickname` on a new\ncustomer.\n\n\nAlternatively, refer to the\n[metafieldsSet](https://shopify.dev/api/admin-graphql/latest/mutations/metafieldsset) mutation\nto create and/or update metafields on customer resources.\n", "query_string": "mutation createCustomerMetafields($input: CustomerInput!) {\n customerCreate(input: $input) {\n customer {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n}", "variables": { "input": { "metafields": [ { "namespace": "my_field", "key": "nickname", "type": "single_line_text_field", "value": "rob" } ], "email": "bob.norman@example.com" } }, "response": { "data": { "customerCreate": { "customer": { "id": "gid://shopify/Customer/1073339463", "metafields": { "edges": [ { "node": { "id": "gid://shopify/Metafield/1069229089", "namespace": "my_field", "key": "nickname", "value": "rob" } } ] } }, "userErrors": [] } } }, "api_name": "admin", "location": "/components/customers/test/unit/graph_api/admin/mutations/customer_create_test.rb", "minimum_api_version": null, "maximum_api_version": null, "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation createCustomerMetafields($input: CustomerInput!) { customerCreate(input: $input) { customer { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }\",\n \"variables\": {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"nickname\",\n \"type\": \"single_line_text_field\",\n \"value\": \"rob\"\n }\n ],\n \"email\": \"bob.norman@example.com\"\n }\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation createCustomerMetafields($input: CustomerInput!) {\n customerCreate(input: $input) {\n customer {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"nickname\",\n \"type\": \"single_line_text_field\",\n \"value\": \"rob\"\n }\n ],\n \"email\": \"bob.norman@example.com\"\n }\n },\n },\n);\n\nconst data = await response.json();\n", "ruby_example": "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation createCustomerMetafields($input: CustomerInput!) {\n customerCreate(input: $input) {\n customer {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"metafields\": [{\"namespace\"=>\"my_field\", \"key\"=>\"nickname\", \"type\"=>\"single_line_text_field\", \"value\"=>\"rob\"}],\n \"email\": \"bob.norman@example.com\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation createCustomerMetafields($input: CustomerInput!) {\n customerCreate(input: $input) {\n customer {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"nickname\",\n \"type\": \"single_line_text_field\",\n \"value\": \"rob\"\n }\n ],\n \"email\": \"bob.norman@example.com\"\n }\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation createCustomerMetafields($input: CustomerInput!) {\n customerCreate(input: $input) {\n customer {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"metafields\" => [{\"namespace\"=>\"my_field\", \"key\"=>\"nickname\", \"type\"=>\"single_line_text_field\", \"value\"=>\"rob\"}],\n \"email\" => \"bob.norman@example.com\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "The input fields to create a customer.", "type": { "kind": "INPUT_OBJECT", "name": "CustomerInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "CustomerInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"metafields\":[{\"namespace\":\"my_field\",\"key\":\"nickname\",\"type\":\"single_line_text_field\",\"value\":\"rob\"}],\"email\":\"bob.norman@example.com\"}", "typeKind": "MUTATION" } ] } ]