Solved

Getting the number of orders in a given timerange in a publicly listed embedded application

akatcha
Tourist
7 1 1

Hi!  

I'm working on an embedded application that needs to get the count of orders from a certain timerange.  I think the graphql way with pagination is a hurdle and difficult to set up, plus it requires me to manually write the querying logic and aggregating the number of orders into a number.  How can I query to get a count of all the orders while avoiding graphql request?    

 

Correct me if I'm wrong (and how to do this if possible) I don't think querying the /admin..orders.json endpoint is feasible since this is an embedded application (publicly listed) and I will not have access to the apikey or apiSecret of the stores this application will integrate with. 

 

Thank you.

Accepted Solution (1)
akatcha
Tourist
7 1 1

This is an accepted solution.

Okay, turns out I figured it out.  

You can use the koa middleware (nodejs) to get the accessToken after proper O-auth.  Then you can send the accessToken as part of the GET request in the header.

const accessToken = ctx.session.accessToken;

const response = await fetch(
        `https://${myShop}myshopify.com/admin/api/2020-07/orders.json?status=any`,
        {
        method: "GET",
        headers: {
         "Content-Type": "application/json",
        "X-Shopify-Access-Token": accessToken
},
}
);

View solution in original post

Replies 4 (4)

msk
Excursionist
28 5 3

hello,

please use this api link from shopify it will count all orders please use filter which orders you are counting.

 

 

/admin/api/2020-07/orders/count.json

 

Thanks

msk
Excursionist
28 5 3

hello,

can you please tell me what kind of orders you want to count. i will send you one script here you just need to run it on BASH. 

then i will explain you in detail that code.

Thanks

akatcha
Tourist
7 1 1

I see everywhere to make the api calls like such: https://{yourapikey}:{yourapikey}@s{yourstore}/admin/orders.json 

If I don't have the apikeys for the store (since it will be a public app), then this request cannot be made. 

Does that make sense?

akatcha
Tourist
7 1 1

This is an accepted solution.

Okay, turns out I figured it out.  

You can use the koa middleware (nodejs) to get the accessToken after proper O-auth.  Then you can send the accessToken as part of the GET request in the header.

const accessToken = ctx.session.accessToken;

const response = await fetch(
        `https://${myShop}myshopify.com/admin/api/2020-07/orders.json?status=any`,
        {
        method: "GET",
        headers: {
         "Content-Type": "application/json",
        "X-Shopify-Access-Token": accessToken
},
}
);