A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I am attempting up update the CustomerEmailMarketingState to "SUBSCRIBED" from "UNSUBSCRIBED" via a graphql mutation. The query is:
mutation {
customerEmailMarketingConsentUpdate(
input: {customerId: "gid://shopify/Customer/{id-here}", emailMarketingConsent: {consentUpdatedAt: "2024-01-09", marketingOptInLevel: CONFIRMED_OPT_IN, marketingState: SUBSCRIBED}}
) {
userErrors {
field
message
}
customer {
email
displayName
emailMarketingConsent {
consentUpdatedAt
marketingOptInLevel
marketingState
}}}}
The result I get is a 200 with the json:
Solved! Go to the solution
This is an accepted solution.
Thanks. After uninstalling and reinstalling the app, I was able to select the correct permissions and run the query in the GraphiQL without the access error.
I figured out the issue and I think this is a bug (or at least there should be some documentation somewhere to explain this situation; I don't see anything here: https://shopify.dev/docs/api/admin-graphql/2024-01/input-objects/CustomerEmailMarketingConsentInput).
If you don't add a "consentUpdatedAt" that is greater than or equal to the existing "consentUpdatedAt" value, the marketingState will not be updated AND you don't receive an error or message explaing why it wasn't updated.
For example, if the "consentUpdatedAt" is '2024-01-16', then in order to update the marketingState, you must pass the "consentUpdatedAt" to be at least '2024-01-16'. You can't set it to '2024-01-15'. While this makes sense, if the "consentUpdatedAt" had a timestamp attached, such as '2024-01-16T01:01:01Z', you couldn't use just '2024-01-16' as the value. You must include a timestamp to make it at least '2024-01-16T01:01:01Z'.
I tested this many times and this seems to be exactly what is happening. If I am wrong, please let me know.
Hi Mnf,
Are you using a client like Postman to make this mutation? If you try making the same mutation with the GraphiQL app, are you seeing the expected change occuring?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
I am using Postman as well as C# and both have the same result.
When I use GraphiQL app, I receive the error "Access denied for customerEmailMarketingConsentUpdate field. Required access: `write_customers` access scope.". My understanding is I don't have the ability to update the access of the app when running through the shopify admin area.
You should be able to update the scopes but you'll need to re-authenticate the app on your test store to accept the new scopes.
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Do you have a link to instructions on how to update the scope?
Hey @mnf,
You should be able to change the access scopes for the Shopify GraphiQL app by uninstalling it from your store, then re-installing with the newly selected scopes via the link Liam shared above.
Custom apps setup in a shop's admin can update their scopes directly in the App's section of the UI, and we have a guide on how to update OAuth scopes as well if that's how your C# app is setup.
Hope that helps!
- James
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This is an accepted solution.
Thanks. After uninstalling and reinstalling the app, I was able to select the correct permissions and run the query in the GraphiQL without the access error.
I figured out the issue and I think this is a bug (or at least there should be some documentation somewhere to explain this situation; I don't see anything here: https://shopify.dev/docs/api/admin-graphql/2024-01/input-objects/CustomerEmailMarketingConsentInput).
If you don't add a "consentUpdatedAt" that is greater than or equal to the existing "consentUpdatedAt" value, the marketingState will not be updated AND you don't receive an error or message explaing why it wasn't updated.
For example, if the "consentUpdatedAt" is '2024-01-16', then in order to update the marketingState, you must pass the "consentUpdatedAt" to be at least '2024-01-16'. You can't set it to '2024-01-15'. While this makes sense, if the "consentUpdatedAt" had a timestamp attached, such as '2024-01-16T01:01:01Z', you couldn't use just '2024-01-16' as the value. You must include a timestamp to make it at least '2024-01-16T01:01:01Z'.
I tested this many times and this seems to be exactly what is happening. If I am wrong, please let me know.