Why Can't I Update Email Marketing Consent in Customer Update Mutation?

What I did:

  1. First I was trying to update only marketingState in customerUpdate mutation - but need to pass all object emailMarketingConsent
  2. After trying to update emailMarketingConsent from customerUpdate mutation - “INTERNAL_SERVER_ERROR”.
  3. Then try update from customerEmailMarketingConsentUpdate mutation - “Cannot update the consent state to not subscribed”

How can I update emailMarketingConsent and what I did wrong?

Examples request and response:

Request URL: https://another-zpawn-store.myshopify.com/admin/api/2022-04/graphql.json
Reauest Payload: {
  query: `
    mutation customerUpdate($input: CustomerInput!) {
      customerUpdate(input: $input) {
        userErrors { field, message },
        customer {
          id, firstName, lastName, email, phone, note,
          emailMarketingConsent { marketingState, consentUpdatedAt, marketingOptInLevel }
        }
      }
    }    
  `,
  variables: {
    input: {
      email: "egnition_sample_59@egnition.com"
      emailMarketingConsent: {
        consentUpdatedAt: "2022-06-04T09:36:53.791Z",
        marketingOptInLevel: "SINGLE_OPT_IN",
        marketingState: "NOT_SUBSCRIBED",
      }
      firstName: "Armen"
      id: "gid://shopify/Customer/6261760852210"
      lastName: "Tamzarian"
    }
  },
}
Response: {
  errors: [{
    extensions: {
      code: "INTERNAL_SERVER_ERROR",
      requestId: "e6f61e7e-d9a1-4b31-809a-2f7a369b7e6b",
    },
    message: "Internal error. Looks like something went wrong on our end.\nRequest ID: e6f61e7e-d9a1-4b31-809a-2f7a369b7e6b (include this in support requests)."
  }]
}
Request URL: https://another-zpawn-store.myshopify.com/admin/api/2022-04/graphql.json
Reauest Payload: {
  query: `
    mutation customerEmailMarketingConsentUpdate($input: CustomerEmailMarketingConsentUpdateInput!) {
        customerEmailMarketingConsentUpdate(input: $input) {
            customer {
                id, emailMarketingConsent {
                    marketingState,
                    consentUpdatedAt,
                    marketingOptInLevel,
                },
            }
            userErrors { field, message }
        }
    }
  `,
  variables: {
    customerId: "gid://shopify/Customer/6261760852210",
    emailMarketingConsent: {
      consentUpdatedAt: "2022-06-04T09:17:12.244Z",
      marketingOptInLevel: "SINGLE_OPT_IN",
      marketingState: "NOT_SUBSCRIBED",
    }
  }
}

Response: {
  userErrors: [{
    field: ["input", "emailMarketingConsent", "marketingOptInLevel"],
    message: "Cannot update the consent state to not subscribed",
  }],
}

Hey @zpawn ,

for:

Request URL: https://another-zpawn-store.myshopify.com/admin/api/2022-04/graphql.json
Reauest Payload: {
  query: `
    mutation customerEmailMarketingConsentUpdate($input: CustomerEmailMarketingConsentUpdateInput!) {
        customerEmailMarketingConsentUpdate(input: $input) {
            customer {
                id, emailMarketingConsent {
                    marketingState,
                    consentUpdatedAt,
                    marketingOptInLevel,
                },
            }
            userErrors { field, message }
        }
    }
  `,
  variables: {
    customerId: "gid://shopify/Customer/6261760852210",
    emailMarketingConsent: {
      consentUpdatedAt: "2022-06-04T09:17:12.244Z",
      marketingOptInLevel: "SINGLE_OPT_IN",
      marketingState: "NOT_SUBSCRIBED",
    }
  }
}

Response: {
  userErrors: [{
    field: ["input", "emailMarketingConsent", "marketingOptInLevel"],
    message: "Cannot update the consent state to not subscribed",
  }],
}

Rather than “not_subscribed”, try “unsubscribed”. We have both values - “not_subscribed” is an initial value that designates a customer who has never been subscribed. You cannot update a subscribed customer back to this value. You would need to use “unsubscribed” instead.

1 Like

@GrahamS very thanks. It works

1 Like