How to query a customers DataSaleOpt out flag

Hello All,
I am interested in obtaining a list from customers who have opted out of data sales, I can see the flag in GraphQL and the wizard wrote the following

query GetCustomersOptedOutOfDataSales {
  customers(first: 10, query: "data_sale_opt_out:true") {
    edges {
      node {
        id
        firstName
        lastName
        email
        dataSaleOptOut
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

However if you execute this within shopfy using the Shopify Graph QL app you get told..

"search": [
      {
        "path": [
          "customers"
        ],
        "query": "data_sale_opt_out:true",
        "parsed": {
          "field": "data_sale_opt_out",
          "match_all": "true"
        },
        "warnings": [
          {
            "field": "data_sale_opt_out",
            "message": "Invalid search field for this query."
          }

I have tried variations datasaleoptout including dataSaleOptOut?

So does this mean, you can’t query it?

Thanks
Lucy

1 Like

Hey @Lucy_hutchinson!

There isn’t currently a query filter available for the dataSaleOptOut field.

Your best option right now is to retrieve customers without the search filter and then filter them client-side based on the dataSaleOptOut field value.

Alternatively, you could implement a tagging system where customers get tagged based on their opt-out status (like “dataSaleOptOutTRUE”), then use the tag search field which is supported. Shopify Flow can help automate adding these tags based on the status: