Version: 2024-04
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"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 } } } }\",\n \"variables\": {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"smsMarketingConsent\": {\n \"marketingState\": \"SUBSCRIBED\",\n \"marketingOptInLevel\": \"SINGLE_OPT_IN\"\n }\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"smsMarketingConsent\": {\n \"marketingState\": \"SUBSCRIBED\",\n \"marketingOptInLevel\": \"SINGLE_OPT_IN\"\n }\n }\n },\n },\n});\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 customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"smsMarketingConsent\": {\n \"marketingState\": \"SUBSCRIBED\",\n \"marketingOptInLevel\": \"SINGLE_OPT_IN\"\n }\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<[\n \"email\" => \"steve.lastnameson@example.com\",\n \"phone\" => \"+16465555555\",\n \"firstName\" => \"Steve\",\n \"smsMarketingConsent\" => [\n \"marketingState\" => \"SUBSCRIBED\",\n \"marketingOptInLevel\" => \"SINGLE_OPT_IN\",\n ],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"smsMarketingConsent\": {\n \"marketingState\": \"SUBSCRIBED\",\n \"marketingOptInLevel\": \"SINGLE_OPT_IN\"\n }\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n }\n }\n}"
input: { "input": { "email": "steve.lastnameson@example.com", "phone": "+16465555555", "firstName": "Steve", "smsMarketingConsent": { "marketingState": "SUBSCRIBED", "marketingOptInLevel": "SINGLE_OPT_IN" } } }
response: { "data": { "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" } } } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"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 } } } }\",\n \"variables\": {\n \"input\": {\n \"email\": null,\n \"phone\": null,\n \"firstName\": null,\n \"lastName\": null\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n emailMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n }\n addresses {\n address1\n city\n countryCode\n phone\n zip\n }\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"email\": null,\n \"phone\": null,\n \"firstName\": null,\n \"lastName\": null\n }\n },\n },\n});\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 customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n emailMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n }\n addresses {\n address1\n city\n countryCode\n phone\n zip\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"email\": null,\n \"phone\": null,\n \"firstName\": null,\n \"lastName\": null\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<[\n \"email\" => null,\n \"phone\" => null,\n \"firstName\" => null,\n \"lastName\" => null,\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n emailMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n }\n addresses {\n address1\n city\n countryCode\n phone\n zip\n }\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"email\": null,\n \"phone\": null,\n \"firstName\": null,\n \"lastName\": null\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n emailMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n }\n addresses {\n address1\n city\n countryCode\n phone\n zip\n }\n }\n }\n}"
input: { "input": { "email": null, "phone": null, "firstName": null, "lastName": null } }
response: { "data": { "customerCreate": { "userErrors": [ { "field": null, "message": "Customer must have a name, phone number or email address" } ], "customer": null } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/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" 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" 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" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<[\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" 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" Graphql 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}"
input: { "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/1073340085", "metafields": { "edges": [ { "node": { "id": "gid://shopify/Metafield/1069230109", "namespace": "my_field", "key": "nickname", "value": "rob" } } ] } }, "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"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 } } } }\",\n \"variables\": {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\",\n \"emailMarketingConsent\": {\n \"marketingOptInLevel\": \"CONFIRMED_OPT_IN\",\n \"marketingState\": \"SUBSCRIBED\"\n },\n \"addresses\": [\n {\n \"address1\": \"412 fake st\",\n \"city\": \"Ottawa\",\n \"province\": \"ON\",\n \"phone\": \"+16469999999\",\n \"zip\": \"A1A 4A1\",\n \"lastName\": \"Lastname\",\n \"firstName\": \"Steve\",\n \"countryCode\": \"CA\"\n }\n ]\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n emailMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n }\n addresses {\n address1\n city\n country\n phone\n zip\n }\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\",\n \"emailMarketingConsent\": {\n \"marketingOptInLevel\": \"CONFIRMED_OPT_IN\",\n \"marketingState\": \"SUBSCRIBED\"\n },\n \"addresses\": [\n {\n \"address1\": \"412 fake st\",\n \"city\": \"Ottawa\",\n \"province\": \"ON\",\n \"phone\": \"+16469999999\",\n \"zip\": \"A1A 4A1\",\n \"lastName\": \"Lastname\",\n \"firstName\": \"Steve\",\n \"countryCode\": \"CA\"\n }\n ]\n }\n },\n },\n});\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 customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n emailMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n }\n addresses {\n address1\n city\n country\n phone\n zip\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\",\n \"emailMarketingConsent\": {\n \"marketingOptInLevel\": \"CONFIRMED_OPT_IN\",\n \"marketingState\": \"SUBSCRIBED\"\n },\n \"addresses\": [{\"address1\"=>\"412 fake st\", \"city\"=>\"Ottawa\", \"province\"=>\"ON\", \"phone\"=>\"+16469999999\", \"zip\"=>\"A1A 4A1\", \"lastName\"=>\"Lastname\", \"firstName\"=>\"Steve\", \"countryCode\"=>\"CA\"}]\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<[\n \"email\" => \"steve.lastnameson@example.com\",\n \"phone\" => \"+16465555555\",\n \"firstName\" => \"Steve\",\n \"lastName\" => \"Lastname\",\n \"emailMarketingConsent\" => [\n \"marketingOptInLevel\" => \"CONFIRMED_OPT_IN\",\n \"marketingState\" => \"SUBSCRIBED\",\n ],\n \"addresses\" => [{\"address1\"=>\"412 fake st\", \"city\"=>\"Ottawa\", \"province\"=>\"ON\", \"phone\"=>\"+16469999999\", \"zip\"=>\"A1A 4A1\", \"lastName\"=>\"Lastname\", \"firstName\"=>\"Steve\", \"countryCode\"=>\"CA\"}],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n emailMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n }\n addresses {\n address1\n city\n country\n phone\n zip\n }\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"email\": \"steve.lastnameson@example.com\",\n \"phone\": \"+16465555555\",\n \"firstName\": \"Steve\",\n \"lastName\": \"Lastname\",\n \"emailMarketingConsent\": {\n \"marketingOptInLevel\": \"CONFIRMED_OPT_IN\",\n \"marketingState\": \"SUBSCRIBED\"\n },\n \"addresses\": [\n {\n \"address1\": \"412 fake st\",\n \"city\": \"Ottawa\",\n \"province\": \"ON\",\n \"phone\": \"+16469999999\",\n \"zip\": \"A1A 4A1\",\n \"lastName\": \"Lastname\",\n \"firstName\": \"Steve\",\n \"countryCode\": \"CA\"\n }\n ]\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation customerCreate($input: CustomerInput!) {\n customerCreate(input: $input) {\n userErrors {\n field\n message\n }\n customer {\n id\n email\n phone\n taxExempt\n emailMarketingConsent {\n marketingState\n marketingOptInLevel\n consentUpdatedAt\n }\n firstName\n lastName\n amountSpent {\n amount\n currencyCode\n }\n smsMarketingConsent {\n marketingState\n marketingOptInLevel\n }\n addresses {\n address1\n city\n country\n phone\n zip\n }\n }\n }\n}"
input: { "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: { "data": { "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" } ] } } } }