What I did:
- First I was trying to update only marketingState in customerUpdate mutation - but need to pass all object emailMarketingConsent
- After trying to update emailMarketingConsent from customerUpdate mutation - “INTERNAL_SERVER_ERROR”.
- 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",
}],
}