--- title: customerEmailMarketingSubscribe - Storefront API description: Subscribes a customer to the newsletter with an email address. api_version: unstable api_name: storefront source_url: html: >- https://shopify.dev/docs/api/storefront/unstable/mutations/customerEmailMarketingSubscribe md: >- https://shopify.dev/docs/api/storefront/unstable/mutations/customerEmailMarketingSubscribe.md --- # customer​Email​Marketing​Subscribe mutation Requires `unauthenticated_write_customers` access scope. Subscribes a customer to the newsletter with an email address. ## Arguments * email [String!](https://shopify.dev/docs/api/storefront/unstable/scalars/String) required The customer's email address. *** ## Customer​Email​Marketing​Subscribe​Payload returns * customer [Customer​Marketing​Subscribe](https://shopify.dev/docs/api/storefront/unstable/objects/CustomerMarketingSubscribe) The created customer object. * customer​User​Errors [\[Customer​User​Error!\]!](https://shopify.dev/docs/api/storefront/unstable/objects/CustomerUserError) non-null The list of errors that occurred from executing the mutation. *** ## Examples * ### Subscribe a customer to your newsletter #### Description Subscribe a customer to your newsletter #### Query ```graphql mutation customerEmailMarketingSubscribe($email: String!) { customerEmailMarketingSubscribe(email: $email) { customer { email } customerUserErrors { field message code } } } ``` #### Variables ```json { "email": "johnsmith@shopify.com" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Storefront-Access-Token: {storefront_access_token}' \ -d '{ "query": "mutation customerEmailMarketingSubscribe($email: String!) { customerEmailMarketingSubscribe(email: $email) { customer { email } customerUserErrors { field message code } } }", "variables": { "email": "johnsmith@shopify.com" } }' ``` #### React Router ```javascript import { unauthenticated } from "../shopify.server"; export const loader = async () => { const { storefront } = await unauthenticated.storefront( 'your-development-store.myshopify.com' ); const response = await storefront.graphql( `#graphql mutation customerEmailMarketingSubscribe($email: String!) { customerEmailMarketingSubscribe(email: $email) { customer { email } customerUserErrors { field message code } } }`, { variables: { "email": "johnsmith@shopify.com" }, }, ); const json = await response.json(); return json.data; } ``` #### Node.js ```javascript const client = new shopify.clients.Storefront({ domain: 'your-development-store.myshopify.com', storefrontAccessToken, }); const data = await client.query({ data: { "query": `mutation customerEmailMarketingSubscribe($email: String!) { customerEmailMarketingSubscribe(email: $email) { customer { email } customerUserErrors { field message code } } }`, "variables": { "email": "johnsmith@shopify.com" }, }, }); ``` #### Response ```json { "customerEmailMarketingSubscribe": { "customer": { "email": "johnsmith@shopify.com" }, "customerUserErrors": [] } } ``` * ### customerEmailMarketingSubscribe reference [Open in GraphiQL](http://localhost:3457/graphiql?query=mutation%20customerEmailMarketingSubscribe\(%24email%3A%20String!\)%20%7B%0A%20%20customerEmailMarketingSubscribe\(email%3A%20%24email\)%20%7B%0A%20%20%20%20customer%20%7B%0A%20%20%20%20%20%20email%0A%20%20%20%20%7D%0A%20%20%20%20customerUserErrors%20%7B%0A%20%20%20%20%20%20field%0A%20%20%20%20%20%20message%0A%20%20%20%20%20%20code%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D\&variables=%7B%0A%20%20%22email%22%3A%20%22johnsmith%40shopify.com%22%0A%7D) ##### GQL ```graphql mutation customerEmailMarketingSubscribe($email: String!) { customerEmailMarketingSubscribe(email: $email) { customer { email } customerUserErrors { field message code } } } ``` ##### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Storefront-Access-Token: {storefront_access_token}' \ -d '{ "query": "mutation customerEmailMarketingSubscribe($email: String!) { customerEmailMarketingSubscribe(email: $email) { customer { email } customerUserErrors { field message code } } }", "variables": { "email": "johnsmith@shopify.com" } }' ``` ##### React Router ```javascript import { unauthenticated } from "../shopify.server"; export const loader = async () => { const { storefront } = await unauthenticated.storefront( 'your-development-store.myshopify.com' ); const response = await storefront.graphql( `#graphql mutation customerEmailMarketingSubscribe($email: String!) { customerEmailMarketingSubscribe(email: $email) { customer { email } customerUserErrors { field message code } } }`, { variables: { "email": "johnsmith@shopify.com" }, }, ); const json = await response.json(); return json.data; } ``` ##### Node.js ```javascript const client = new shopify.clients.Storefront({ domain: 'your-development-store.myshopify.com', storefrontAccessToken, }); const data = await client.query({ data: { "query": `mutation customerEmailMarketingSubscribe($email: String!) { customerEmailMarketingSubscribe(email: $email) { customer { email } customerUserErrors { field message code } } }`, "variables": { "email": "johnsmith@shopify.com" }, }, }); ``` ## Input variables JSON ```json { "email": "johnsmith@shopify.com" } ``` ## Response JSON ```json { "customerEmailMarketingSubscribe": { "customer": { "email": "johnsmith@shopify.com" }, "customerUserErrors": [] } } ```