I’m running into an interesting situation where when I query orders using GraphQL to get the fulfillmentOrders, I am unable to get the lineItems product data.
Here’s an example query (some details removed/truncated):
{
order(id: "gid://shopify/Order/12345") {
currencyCode
fulfillmentOrders(first: 10) {
nodes {
id
status
lineItems(first: 50) {
nodes {
id
productTitle
variantTitle
totalQuantity
}
}
}
}
lineItems(first: 50) {
nodes {
id
currentQuantity
quantity
product {
id
title
m_reference: metafield(namespace: "m", key: "reference") {value}
m_color_code: metafield(namespace: "m", key: "color_code") {value}
}
variant {
sku
title
m_size_code: metafield(namespace: "m", key: "size_code") {value}
}
}
}
}
}
In this example above, I’m needing to grab metafield data from the underlying lineitem product and variant data.
However, the problem is that I need to do this while under the fulfillmentOrders object so because I’m looking at lineitems per fulfillment order. There’s currently no way for me to know what the product details are for each line item while I’m iterating over each fulfillmentOrders order.
I’m unable to tie products together between order.fulfillmentOrders.lineItems to order.lineItems by SKU… and the “id” in order.fulfillmentOrders.lineItems is for the fulfillment Line Item ID, not the product ID.
Thoughts?
Also worth noting that I can’t solely use order.lineItems because then I don’t know what fulfillment order they belong to.
My goal would be to pull order.fulfillmentOrders.lineItems and see all relevant product/variant details that I need for our fulfillment.
Hey @Rob-Widdick - great question, info and use-case here. Right out of the gate, not all resources are able to implement metafields - there is a complete list available here.
FulfillmentOrder.lineItem and Order.lineItem reference different root objects, and their connection will be to independent LineItem objects; a good way to visualize this is through each gid (global identifier) structure. There isn’t a direct relationship between those objects, rather a more indirect relationship that you may be able to map through the variant/product. While FulfillmentOrder.lineItem doesn’t offer a full connection to the Variant or Product objects, productTitle and variantTitle can be returned on this object.
Working through a few test queries using our docs, my test app, and an API client (Insomnia), I was able to draft up an example query reworked from the one shared in your initial post. While querying for an order with the id as an argument, I have opted to also return the Order object through a connection on FulfillmentOrder, and then add in additional variant, product and metafields data from there.
query getOrderAndFulfillmentOrderWithMetafields {
order(id: "gid://shopify/Order/${order.id}") {
fulfillmentOrders(first: 5) {
nodes {
id
status
order {
lineItems(first: 10) {
nodes {
id
sku
variant {
id
title
m_reference: metafield(namespace: "*", key: "*") {
value
type
ownerType
}
m_color_code: metafield(namespace: "*", key: "*") {
value
type
ownerType
}
product {
id
m_reference: metafield(namespace: "*", key: "*") {
value
type
ownerType
}
}
}
}
}
}
lineItems(first: 10) {
nodes {
id
sku
variantTitle
productTitle
}
}
}
}
}
}
Hope those insights help clarify and provide another approach towards you solution!
Cheers - @awwdam
Shopify Developer Support
1 Like
Thank you for the answer! This makes sense and after some slight modifications on my end, this worked perfectly. I can now attribute line item details to fulfillment orders 