Shopify API Node: AdminAPI vs StoreFrontAPI Queries

annahernandez99
New Member
3 0 0

I am trying to make a graphql request to shopify's admin api. I am using the official shopify-api-node library.

My query is as follows

const response = await shopify.graphql(`
{
order(id:"<some order id>") {
currentCartDiscountAmountSet {
shopMoney {
amount
currencyCode
}
}
}
}
`);
From my understanding, this should return an object with a data field and an extensions field (I'm interested in query cost).

The response I get is simply contains order.

According to your answer at here, this is because I'm querying storefront API. I'm confused because I want to query admin api. According to shopify docs, order under storefront API does not have the field currentCartDiscountAmountSet, whereas order under admin API does have this field. I am getting the correct order with the field currentCartDiscountAmountSet, and so I presume that I'm querying admin api. But then again, I'm not getting data and extensions?

My questions are:

When using shopify-api-node, how to I specify if I want to query admin or storefront API?

Why am I not getting data and extensions in my response? Is it actually because I'm querying storefront api? If so, then why am I successfully able to get currentCartDiscountAmountSet?

0 Likes
annahernandez99
New Member
3 0 0

Plz also let me know 

I need to load products on my home page.

I try a lot but not getting any success.

Can any help me to short out my problem?

0 Likes
CelinaFregoso
New Member
3 0 0

First and foremost shopify-api-node support only GraphQL Admin API, it doesn't support Storefront API.

Second the Storefront API doesn't have access to the order object directly. You can get a customer orders with the storefront api but for that you need username and password to create the token for that user in order to request his orders or to say it simply you won't be doing that with nodejs or to be more precise it's too much work when you can just use the Admin API. (the API docs is really confusing on this one)

So i think this answer your first question, you can't specify if you are targeting the storefront or admin api, you are stuck with the admin api with this package.

As for your second question I assume that you are passing the wrong ID or something else. Do you pass it properly with id: "gid://shopify/Order/YOUR_ORDER_ID" or you are passing it just with id: "YOUR_ORDER_ID", since the second is wrong. There may be another issue but without knowing the full extend of the flow you will need to debug this on your side.

Here is an image with a sample request that returns what you want. So the request is OK, there is something else that is wrong with your current flow.

shopify01.jpg

0 Likes