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.
Solved

How do I query the cart line properties attribute?

aashby13
Shopify Partner
9 3 0

I am trying to query some custom data from the properties attribute from cart lines but failing.

Neither of the following works. Any suggestions? Is it possible?

 

 

query RunInput {
  cart {
    lines {
      id
      quantity
      attribute(key: "properties") {
        value
      }
    }
  }
}
query RunInput {
  cart {
    lines {
      id
      quantity
      attribute(key: "properties") {
        custom_data: value
      }
    }
  }

 

 

Accepted Solution (1)
aashby13
Shopify Partner
9 3 0

This is an accepted solution.

I managed to figure it out. Data added to the properties attribute are considered to be custom properties, so one just has to target the key of that custom property.

query RunInput {
  cart {
    lines {
      id
      quantity
      custom_data: attribute(key: "_custom_data") {
        value
      }
    }
  }

View solution in original post

Replies 4 (4)

MastersHub
Shopify Partner
197 20 33

You can't use all properties. Instead, you should use the 'properties' key. For example:

 

attribute(key: "discount") {
  key
  value
}

Helpful ? Like and Accept Solution
Buy me a Coffee
Need a Shopify Developer?
Send Email or Chat on WhatsApp
aashby13
Shopify Partner
9 3 0

Thanks, but I'm not trying to get all the properties. I'm trying to get the attribute 'properties', the key is 'properties'. Custom data is added to that when the product is added to cart.

 

From the cart.json:

 Screen Shot 2024-01-25 at 12.45.06 AM.png

MastersHub
Shopify Partner
197 20 33

Are you sure it's dependent on the Cart Line properties field? If it is associated with the cart, you should do it like this.

 

query RunInput {
  cart {
attribute(key: "properties") {
value
} lines { id quantity } } }

 

Helpful ? Like and Accept Solution
Buy me a Coffee
Need a Shopify Developer?
Send Email or Chat on WhatsApp
aashby13
Shopify Partner
9 3 0

This is an accepted solution.

I managed to figure it out. Data added to the properties attribute are considered to be custom properties, so one just has to target the key of that custom property.

query RunInput {
  cart {
    lines {
      id
      quantity
      custom_data: attribute(key: "_custom_data") {
        value
      }
    }
  }