What's your biggest current challenge? Have your say in Community Polls along the right column.
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.

Cannot set the customer’s sms consent

Solved

Cannot set the customer’s sms consent

dev00
Shopify Partner
1 0 0
Problem: I need to unsubscribe the Customer on SMS.

Error:
sms_marketing_consent - Cannot set the customer’s sms consent
Passed parameter:

 

[
    "accepts_marketing" => false,
    "accepts_marketing_updated_at" => $date,
    "email_marketing_consent" => [
        "state" => "subscribed",
        "opt_in_level" => "confirmed_opt_in",
        "consent_updated_at" => $date,
    ],
    "phone" => "+642102912345",
    "sms_marketing_consent" => [
        "state" => "subscribed",
        "opt_in_level" => "single_opt_in",
        "consent_updated_at" => $date,
        "consent_collected_from" => "OTHER",
    ],
    "verified_email" => true,
]

 

Error is thrown when I change ['sms_marketing_consent']['state'] value from subscribed to not_subscribed.
And setting the whole property ['sms_marketing_consent'] to null doesn't also work.

The workaround I found to solve this problem on unsubscribing in SMS is to invoke two(2) endpoints.
1. Update the Customer.

[
    "phone" => null,
    "sms_marketing_consent" => null,
]

Setting the sms_marketing_consent property to null as well as the phone number.
2. Update the Customer.

[
    "phone" => "+642102912345",
]

Set the phone number back.

This seems to be working but is there a way to do it in one swoop?

Accepted Solution (1)

kevnob
Shopify Staff
11 3 3

This is an accepted solution.

Hey @dev00 ,

 

Thanks for your post.

 

I did some digging and found this GraphQL mutation and example for unsubscribing to sms marketing worked really well! I tested it as well with the mutation below.

 

mutation customerSmsMarketingConsentUpdate($input: CustomerSmsMarketingConsentUpdateInput!) {
  customerSmsMarketingConsentUpdate(input: $input) {
    userErrors {
      field
      message
    }
    customer {
      id
      phone
      smsMarketingConsent {
        marketingState
        marketingOptInLevel
        consentUpdatedAt
        consentCollectedFrom
      }
    }
  }
}

 

Variables

 

{
"input": {
"customerId": "gid://shopify/Customer/customerid",
"smsMarketingConsent": {
"marketingOptInLevel": "SINGLE_OPT_IN",
"marketingState": "UNSUBSCRIBED"
}
}
}

 

Note: customerid would need to be changed to the customerid you would like to alter. 

 

Hope this helps! 

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Reply 1 (1)

kevnob
Shopify Staff
11 3 3

This is an accepted solution.

Hey @dev00 ,

 

Thanks for your post.

 

I did some digging and found this GraphQL mutation and example for unsubscribing to sms marketing worked really well! I tested it as well with the mutation below.

 

mutation customerSmsMarketingConsentUpdate($input: CustomerSmsMarketingConsentUpdateInput!) {
  customerSmsMarketingConsentUpdate(input: $input) {
    userErrors {
      field
      message
    }
    customer {
      id
      phone
      smsMarketingConsent {
        marketingState
        marketingOptInLevel
        consentUpdatedAt
        consentCollectedFrom
      }
    }
  }
}

 

Variables

 

{
"input": {
"customerId": "gid://shopify/Customer/customerid",
"smsMarketingConsent": {
"marketingOptInLevel": "SINGLE_OPT_IN",
"marketingState": "UNSUBSCRIBED"
}
}
}

 

Note: customerid would need to be changed to the customerid you would like to alter. 

 

Hope this helps! 

To learn more visit the Shopify Help Center or the Community Blog.