Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

Query Shopify products from a Collection and get product tags

njagojevic
Visitor
2 0 0

How can I get product tags by making a query for products in a specific collection? The error I get here: No field of name "tags" found on type "Product" in schema

const query = shopifyClient.graphQLClient.query((root) => {
      root.add(
        "collectionByHandle",
        { args: { handle: "collection-handle" }, alias: "collection" },
        (Collection) => {
          Collection.add("id");
          Collection.addConnection(
            "products",
            {
              args: {
                first: 25,
              },
            },
            (Product) => {
              Product.add("title");
              Product.add("handle");
              Product.add("tags"); /* Couldn't get tags?! */
              Product.addConnection(
                "variants",
                { args: { first: 25 } },
                (Variant) => {
                  Variant.add("price");
                }
              );
              Product.addConnection(
                "images",
                { args: { first: 1 } },
                (Image) => {
                  Image.add("src");
                }
              );
            }
          );
        }
      );
    });

    shopifyClient.graphQLClient
      .send(query)
      .then(({ model }) => {
        // Some logic
      })
      .catch((err) => {
        console.log("err", err);
      });

 Any suggestions here? Thanks in advance.

Replies 3 (3)

Gregarican
Shopify Partner
1033 86 282

Must be a quirk in the client library you are using. If you refer to a post that I replied to just today, you'll see that the GraphQL query in its raw form successfully retrieves the product tags. Tested it out before I hit the Post button!

 

https://community.shopify.com/c/Shopify-APIs-SDKs/When-I-tried-to-get-the-products-under-a-collectio...

 

njagojevic
Visitor
2 0 0

The library I'm using is https://github.com/Shopify/js-buy-sdk

msk
Excursionist
28 5 3

Hello,

can you please share the URl where you are requesting. if its a link for collection like

"/admin/api/2020-07/collections/841564295.json"

then error is good because there is no tag in it. and if you are using

"/admin/api/2020-07/collections/{collection_id}/products.json"

then this error should not come.