Cannot set the customer’s sms consent

Problem: I need to unsubscribe the Customer on SMS.

Error:

sms_marketing_consent - Cannot set the customer’s sms consentPassed 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?

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!