We’re developing an web app and we’re using the Storefront API on the client. We create a checkout on the clients and to complete the checkout we post the checkout id and some other data to an endpoint which uses the Admin API to create an order for the checkout. We get the order id back from that endpoint but when I try to query for the Order via the Storefront API I cannot seem to get a response. I always get null.
The Admin API uses clean ids while the Storefront API uses base64 encoded string for ids. I kind of just guessed the string to encode was in the form of gid://shopify/Order/<id>. So the order id I get from the endpoint is for example 521899273 so I encode gid://shopify/Order/521899273 and get Z2lkOi8vc2hvcGlmeS9PcmRlci81MjE4OTkyNzM= which I use to fetch the Order like so:
{
node(id: "Z2lkOi8vc2hvcGlmeS9PcmRlci81MjE4OTkyNzM=") {
id
... on Order {
id
totalPrice
subtotalPrice
totalTax
lineItems(first: 250) {
edges {
node {
quantity
title
}
}
}
}
}
}
But this does not return the order. What are we doing wrong?
We were facing the same challenge of getting order details for a single order. From the looks of your ID, you’re missing a hidden ?key= parameter. Unfortunately, I can’t find much information about what that is. But I can just tell you how we’re getting it to populate an order detail page in the user’s account section.
Here’s the steps we’re using to get order details (please note, we’re using API version 2020-04 here):
First, we get the customer access token using the following mutation:
Lastly, we get the order details of a specific order using the “globally unique identifier” returned from step two on the Node object:
{
node(id: "BASE_64_ENCODED_ID") {
... on Order {
id
totalPrice
subtotalPrice
totalTax
lineItems(first: 250) {
edges {
node {
quantity
title
}
}
}
}
}
}
The order ID returned for each order in step two above is a base64 encoded string following this syntax:
gid://shopify/Order/ORDER_ID?key=SOME_SECRET_KEY
Again, I’m not clear on what exactly is the SOME_SECRET_KEY portion, but I can tell you that it’s included in the ID returned in step 2 when fetching a list of orders for a specific customer.