What's your biggest current challenge? Have your say in Community Polls along the right column.

Issue with hasTags Returning false in Shopify functions run.graphql file: GraphQL API Despite Tag Pr

Issue with hasTags Returning false in Shopify functions run.graphql file: GraphQL API Despite Tag Pr

muhammadhassaan
Shopify Partner
1 0 0

I’m encountering an issue with the Shopify GraphQL API when trying to set up customization rules based on customer tags. Here’s the situation:

I’ve created a rule where users can specify a tag for a customer. This involves the following conditions:

  • Condition Option: CustomerTag
  • Condition: Contains
  • A field is provided for the user to input the desired customer tag (e.g., TestingC-Tag).

The tag is successfully added and saved in the Shopify Admin under Customers Settings. However, when I query the hasTags field in the buyerIdentity.customer object, it is returning false for the hasTag property, even though the tag exists for the customer.

GraphQL Query:

query ($customerTags: [String!]) {
  buyerIdentity {
    email
    customer {
      email
      amountSpent {
        amount
      }
      hasTags(tags: $customerTags) {
        tag
        hasTag
      }
    }
  }
}

run.graphql :

query RunInput($customerTags: [String!], $productTags: [String!]) {
  cart {
    discountCodes: attribute(key: "discountCodes") {
      key
      value
    }
    zoneProvince: attribute(key: "Zone") {
      key
      value
    }
    cost {
      totalAmount {
        amount
      }
      totalTaxAmount{
        amount 
      }
      subtotalAmount {
        amount
      }
    }
      
    lines {
      quantity
      cost{
        amountPerQuantity{
          amount
        }
        compareAtAmountPerQuantity{
          amount
        }
      }
      merchandise {
        ... on ProductVariant {
          sku
          weight
          product {
            hasTags(tags: $productTags) {
              tag
              hasTag
            }
          }
        }
      }
    }
    deliveryGroups {
      deliveryAddress {
        provinceCode
        city
        countryCode
      }
      selectedDeliveryOption {
        cost {
          amount
        }
      }
    }
    buyerIdentity {
      email
      customer {
        email
        amountSpent {
          amount
        }
        hasTags(tags: $customerTags) {
          tag
          hasTag
        }
      }
    }
  }
  paymentMethods {
    id
    name
  }
  paymentCustomization {
    metafield(namespace: "$app:payment-customization-v2", key: "advance-rules") {
      value
    }
  }
}

 

Result from Extensions Console:

{
  "buyerIdentity": {
    "email": "userxyz@gmail.com",
    "customer": {
      "email": "userxyz@gmail.com",
      "amountSpent": {
        "amount": "0.0"
      },
      "hasTags": [
        {
          "tag": "TestingC-Tag",
          "hasTag": false
        }
      ]
    }
  }
}

As you can see, the API is returning hasTag: false for the tag "TestingC-Tag", even though it exists in the Shopify Admin for this customer.

Steps I’ve Taken:

  1. Verified that the tag "TestingC-Tag" is correctly added and visible in Shopify Admin under the customer’s profile.
  2. Confirmed the GraphQL query syntax and input data.
  3. Rechecked the customerTags value being passed to ensure it matches the tag in Shopify Admin.

Question:

Why might the hasTags field be returning false for a tag that exists in Shopify Admin? how do i fix reslve it to use hasTag or is there any other solution to use CustomerTags?



Replies 0 (0)