New Shopify Certification now available: Liquid Storefronts for Theme Developers

Shopify GraphQL customerSmsMarketingConsentUpdate mutation not working.

ThomasLi
Shopify Partner
1 0 0

 

mutation customerEmailMarketingConsentUpdate ($input: CustomerEmailMarketingConsentUpdateInput!) {
  customerEmailMarketingConsentUpdate(input: $input) {
    customer {
      id
      email
      emailMarketingConsent {
        marketingState
        consentUpdatedAt
        marketingOptInLevel
      }
    }
    userErrors {
      field
      message
    }
  }
}

{
"input": {
"customerId": "gid://shopify/Customer/**************",
"emailMarketingConsent": {
"marketingState": "UNSUBSCRIBED"
}
}
}

 

{
  "data": {
    "customerEmailMarketingConsentUpdate": {
      "customer": {
        "id": "gid://shopify/Customer/**************",
        "email": "**************@email.com",
        "emailMarketingConsent": {
          "marketingState": "UNSUBSCRIBED",
          "consentUpdatedAt": "2023-10-11T03:20:30Z",
          "marketingOptInLevel": "SINGLE_OPT_IN"
        }
      },
      "userErrors": []
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 11,
      "actualQueryCost": 11,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 989,
        "restoreRate": 50
      }
    }
  }
}

When query by customer id:

 

query ($id: ID!) {
  customer(id: $id) {
    id
    email
    emailMarketingConsent {
      consentUpdatedAt
      marketingState
      marketingOptInLevel
    }
  }
}

{
"id": "gid://shopify/Customer/**************"
}
{
  "data": {
    "customer": {
      "id": "gid://shopify/Customer/**************",
      "email": "**************@email.com",
      "emailMarketingConsent": {
        "consentUpdatedAt": "2023-10-11T03:20:33Z",
        "marketingState": "SUBSCRIBED",
        "marketingOptInLevel": "SINGLE_OPT_IN"
      }
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 2,
      "actualQueryCost": 2,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 998,
        "restoreRate": 50
      }
    }
  }
}

 

 

Replies 0 (0)