Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Admin GraphQL customerEmailMarketingConsentUpdate

Solved

Admin GraphQL customerEmailMarketingConsentUpdate

mnf
Excursionist
17 1 12

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:

 

{
    "data": {
        "customerEmailMarketingConsentUpdate": {
            "userErrors": [],
            "customer": {
                "email": "customer-email",
                "displayName": "customer-name",
                "emailMarketingConsent": {
                    "consentUpdatedAt": "2024-01-09T13:18:08Z",
                    "marketingOptInLevel": "CONFIRMED_OPT_IN",
                    "marketingState": "UNSUBSCRIBED"
                }
            }
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 11,
            "actualQueryCost": 11,
            "throttleStatus": {
                "maximumAvailable": 2000.0,
                "currentlyAvailable": 1989,
                "restoreRate": 100.0
            }
        }
    }
}
 
Notice that the marketingState is still "UNSUBSCRIBED".  Any thoughts on why this isn't being changed to "SUBSCRIBED"?
 
Thanks
Accepted Solution (1)
mnf
Excursionist
17 1 12

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.

View solution in original post

Replies 6 (6)

Liam
Community Manager
3108 344 899

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

mnf
Excursionist
17 1 12

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.

Liam
Community Manager
3108 344 899

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

mnf
Excursionist
17 1 12

Do you have a link to instructions on how to update the scope?

ShopifyDevSup
Shopify Staff
1453 238 527

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

mnf
Excursionist
17 1 12

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.