# Query to fetch values of custom attributes on CatalogItems

**URL:** <https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898>\
**Category:** Questions\
**Tags:** graphql-api\
**Created:** [January 22, 2024, 2:49am UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898 "2024-01-22T02:49:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevmo9000](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@kevmo9000](https://developer.squareup.com/forums/u/kevmo9000)\
**Post date:** [January 22, 2024, 2:49am UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898/1 "2024-01-22T02:49:19Z")

</div>

I’m looking for a GraphQL query example on how to get the value of custom attributes on Catalog Items. Is this supported or do I have to use the standard API?

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [January 22, 2024, 6:37pm UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898/2 "2024-01-22T18:37:55Z")

</div>

Yes, custom attributes are supported with GraphQL. What error’s are you getting when trying to retrieve the catalog objects custom attributes? 🙂

---

<div class="post-metadata">

**Author:** ![kevmo9000](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@kevmo9000](https://developer.squareup.com/forums/u/kevmo9000)\
**Post date:** [January 23, 2024, 8:37pm UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898/3 "2024-01-23T20:37:32Z")

</div>

What I’d like to do is to search the catalog for my menu items, and have the returned objects have their custom attributes included. For example, I have an attribute for the number “Servings” the item provides and another for whether it is “Popular.”

Working with the Square GraphQL schema a bit more I realized the _customAttributes_ field hangs off the _variations_ field of a CatalogItem. Even though there is a _customAttributes_ field at the Item level it seems to always be null.

Additionally custom attributes in the list is one of CatalogCustomAttributeUnion type and each attribute type has to be handled separately and aliased. No problem so far, except documentation around this would save devs time (see my queries below).

However there seems to be some bugs.

BUG #1) I’d like to get the name of the attribute not just the value so I can disambiguate it from others of the same type. However the definition field for the attribute returns null for the name field. That said, I can get the IDs for all the custom attribute objects and do a post query join in the code before returning my GraphQL response to my client (this is the point of the second query below in the combined query). However, this is kludgy and should be unnecessary.

BUG #2) Secondly if a Selection type attribute has multiple distinct values on a variation the returned uids list have all the same values. For example, I have a Dietary Preferences custom attribute with Gluten Free, Vegan and Vegatarian as allowed selections. In the Square web UI I set an item to say, vegan and vegetarian. But when I make a GraqhAPI call for it I get two duplicate uids for the selections. (I’m happy to share an example response if that helps). The V2 REST API does not exhibit this bug.

```auto
query CatalogItemsQuery {
  catalogItems(
    filter: {merchantId: {equalToAnyOf: "..."}, 
      enabledLocationId: "...", 
      customAttribute: {id: "...", bool: true}
    }
  ) {
    nodes {
      id
      name
      variations {
        customAttributes {
          definition {
            id
            name # <<< this always comes back NULL
          }
          value {
            ... on CatalogCustomAttributeBoolean {
              boolValue: value
            }
            ... on CatalogCustomAttributeString {
              stringValue: value
            }
            ... on CatalogCustomAttributeSelection {
              uids
            }
            ... on CatalogCustomAttributeNumber {
              numberValue: value
            }
          }
        }
        priceMoney {
          amount
        }
      }
    }
    
  }
  catalog (
    filter: { 
      merchantId: { 
        equalToAnyOf: "..."
      },
			type: {
        equalToAnyOf: [CUSTOM_ATTRIBUTE_DEFINITION]
      }
    }
  ) {
    nodes {
      ... on CatalogCustomAttributeDefinition {
        __typename
        id
        type
        name
        config {
          ... on CatalogCustomAttributeSelectionConfig {
          		allowedSelections {
          		  uid
          		  name
          		}
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![josh-square](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@josh-square](https://developer.squareup.com/forums/u/josh-square)\
**Post date:** [January 24, 2024, 6:42pm UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898/4 "2024-01-24T18:42:43Z")

</div>

Hey @kevmo9000! Do you mind sharing that example response? I’ll try to reproduce this with my own account.

---

<div class="post-metadata">

**Author:** ![kevmo9000](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@kevmo9000](https://developer.squareup.com/forums/u/kevmo9000)\
**Post date:** [January 25, 2024, 5:09am UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898/5 "2024-01-25T05:09:54Z")

</div>

Hi @josh-square,

Here is a fragment of the response that shows the described bugs:

```auto
       {
          "id": "FGPDLGII346YUGCVY6TWYJOP",
          "name": "Cornbread (24 count)",
          "description": "Moist and healthy vegan cornbreads made with coconut oil instead of butter.",
          "category": {
            "name": "Catering",
            "id": "LRBXWTKZ46U6CDCSWT74NG23"
          },
          "images": null,
          "variations": [
            {
              "customAttributes": [
                {
                  "definition": {
                    "id": "VVIZIP4T7DS3LXMFDV57KFLP",
                    "type": null,
                    "key": null,
                    "name": null
                  },
                  "value": {
                    "boolValue": true
                  }
                },
                {
                  "definition": {
                    "id": "XJ5LBWG5OYEOMDLNGE74IEWM",
                    "type": null,
                    "key": null,
                    "name": null
                  },
                  "value": {
                    "uids": [
                      "66QP5JAFFKU37ZIAX6WLPPBG",
                      "66QP5JAFFKU37ZIAX6WLPPBG"
                    ]
                  }
                },
                {
                  "definition": {
                    "id": "6RGSVJQXWMGSDXSO6QWL2OLN",
                    "type": null,
                    "key": null,
                    "name": null
                  },
                  "value": {
                    "numberValue": "24.0"
                  }
                },
                {
                  "definition": {
                    "id": "ROQ7VPKLCL3LHZ6VNQEGSPXB",
                    "type": null,
                    "key": null,
                    "name": null
                  },
                  "value": {
                    "boolValue": true
                  }
                }
              ],
              "priceMoney": {
                "amount": ...
              }
            }
          ]
        }

```

Let me know if you need anything else.

---

<div class="post-metadata">

**Author:** ![josh-square](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@josh-square](https://developer.squareup.com/forums/u/josh-square)\
**Post date:** [January 26, 2024, 11:58pm UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898/6 "2024-01-26T23:58:06Z")

</div>

Do you mind sharing the Merchant ID that you’re querying as well?

---

<div class="post-metadata">

**Author:** ![kevmo9000](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@kevmo9000](https://developer.squareup.com/forums/u/kevmo9000)\
**Post date:** [January 27, 2024, 12:14am UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898/7 "2024-01-27T00:14:09Z")

</div>

I sent it to you via DM on Discord.

---

<div class="post-metadata">

**Author:** ![josh-square](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@josh-square](https://developer.squareup.com/forums/u/josh-square)\
**Post date:** [January 30, 2024, 12:58am UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898/8 "2024-01-30T00:58:59Z")

</div>

Thanks for the heads up! We’ll look into it.

---

<div class="post-metadata">

**Author:** ![kevmo9000](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@kevmo9000](https://developer.squareup.com/forums/u/kevmo9000)\
**Post date:** [February 4, 2024, 12:49am UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898/9 "2024-02-04T00:49:28Z")

</div>

Hi Josh,

Any update here?

Thanks,  
Kevin

---

<div class="post-metadata">

**Author:** ![kevmo9000](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@kevmo9000](https://developer.squareup.com/forums/u/kevmo9000)\
**Post date:** [March 5, 2024, 3:28pm UTC](https://developer.squareup.com/forums/t/query-to-fetch-values-of-custom-attributes-on-catalogitems/11898/10 "2024-03-05T15:28:37Z")

</div>

Okay, so it looks like Bug#1 is fixed, but Bug#2 is still extant. I’m getting all duplicate UIDs for custom attributes of type `CatalogCustomAttributeSelection when there are multiple selections.
