Reputation: 739
How does one get a list of orders from the shopify Graphql api? I can't even figure out how to get a single order. The nearest I can tell is that my query should look something like this:
query{
node(id:$id){
__typename
... on Order{
id
email
}
}
}
Where $id
is "An object with an ID to support global identification" according to the docs, but its not clear what that means. For a product, you can retrieve the id like so:
shop {
productByHandle(handle: "red-bicycle") {
id
}
}
Which will then return a hash, like this:
Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyODE0NzU=
You can then query a product using the node interface like this:
node(id: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyODE0NzU=") {
id
... on Product {
title
}
}
But how is this done for an order? For a list of the most recent 5 orders? Why do you have to use the Node interface at all? Why not just query by handle or ID or something instead of using the hash?
Upvotes: 1
Views: 6496
Reputation: 797
You can use this query for fetch your users orders list
let query = Storefront.buildQuery { $0
.customer(customerAccessToken: token) { $0
.orders(first: 20) { $0
.edges { $0
.node { $0
.id()
.orderNumber()
.totalPrice()
.currencyCode()
.customerLocale()
.customerUrl()
.email()
.phone()
.processedAt()
.subtotalPrice()
.totalRefunded()
.totalShippingPrice()
.totalTax()
.shippingAddress( { $0
.address1()
.address2()
.city()
.company()
.country()
.countryCode()
.firstName()
.formatted()
.formattedArea()
.lastName()
.latitude()
.longitude()
.name()
.phone()
.province()
.provinceCode()
.zip()
})
.lineItems(first: 50) { $0
.edges { $0
.cursor()
.node { $0
.quantity()
.title()
.variant{ $0
.id()
.image({ $0
.altText()
.id()
.src()
})
.price()
.sku()
}
.customAttributes{ $0
.key()
.value()
}
}
}
}
}
}
}
}
}
This query return user's orders list in iOS, Hopefully it will be work for you.
Upvotes: 2