Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
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?
Any help on this?
need the same help.
I can use Admin Graphql to get Order
curl -H "X-Shopify-Access-Token: xxxxxxxxx" -H "Content-Type: application/graphql" https://connecty-store.myshopify.com/admin/api/2019-10/graphql.json -d 'query { node(id: "gid://shopify/Order/xxxxx") { ... on Order {id email }}}'
but I can't get Order by Storefront Graphql
curl -H "X-Shopify-Storefront-Access-Token: #########" -H "Content-Type: application/graphql" https://connecty-store.myshopify.com/api/2019-10/graphql.json -d 'query { node(id: {base64 code}) { ... on Order {id email }}}'
the response is {"data":{"node":null}}
But Order can be found in Storefront API > API reference > Queryable objects > Order.
What do I misunderstand?
Hi Baldur_Helgason,
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):
mutation customerAccessTokenCreate($input: CustomerAccessTokenCreateInput!) { customerAccessTokenCreate(input: $input) { customerAccessToken { accessToken expiresAt } customerUserErrors { code field message } } }The input for that is:
{ "input": { "email": "CUSTOMER@EMAIL.COM", "password": "PASSWORD" } }You'll obviously need to replace the customer's email and password with their credentials.
{ customer(customerAccessToken: "CUSTOMER_ACCESS_TOKEN") { id, firstName, lastName, orders(first: 10) { edges { node { id name totalPrice fulfillmentStatus } } } } }
{ 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.
Hope this helps! Better late than never!
Thanks,
-Noerbot