Rest API returning undefined when fetching all orders

w3d0nts1eep
Shopify Partner
2 0 1

Hi,

 

Hoping someone can help as I've been stuck on this for over a week now and have tried various methods, but I am struggling to fetch all my orders using the shopify API in the template app. I can fetch order count no problem, but I am struggling with fetching the open orders. Here's the code I am using: 

 

 

 

 

app.get("/api/orders", async (_req, res) => {
  const orderData = await shopify.api.rest.Order.all({
    session: res.locals.shopify.session,
    status: "open",
  });
  res.status(200).send(orderData);
});

 

 

 

 

Thanks,

Replies 2 (2)

flareAI
Shopify Partner
2405 223 535

Hello @w3d0nts1eep,

 

I am Gina from flareAI app helping Shopify merchants get $6Million+ in sales from Google Search, on autopilot. Hope you are having a good day.


There might be a problem with the code you provided.


1. Ensure that you have properly authenticated the API request. Make sure that `res.locals.shopify.session` contains the valid credentials required to access the Shopify API.

2. Confirm that you are using the correct API endpoint to fetch orders. The correct endpoint for fetching all orders is `"/admin/api/2023-01/orders.json"`. Make sure that you are making the API call to the correct URL.

3. Ensure that the order status parameter is set correctly. In your code snippet, you are passing `status: "open"`. Double-check that this is the correct value to retrieve open orders. You can also try removing the `status` parameter temporarily to fetch all orders regardless of their status.

4. If you have a large number of orders, the API response might be paginated. Make sure you handle pagination properly to retrieve all orders.

5. Check if there are any error messages or exceptions being thrown during the API call. Make sure you have appropriate error handling in place to capture and handle any errors that may occur during the API request.


By reviewing and addressing these aspects, you should be able to troubleshoot the issue of fetching all orders using the Shopify REST API in your app.


Gina

flareAI : Get Sales from Google Search, on Autopilot
$10+ billion in eCommerce on Google Search, every day. Find out how much you are missing

remy727
Shopify Partner
40 2 22

1. Can you double check if shopify.api.rest.Order is correct? I think shopify.rest.Order is correct.
2. If shopify.api.rest.Order is correct, can you try to fetch any orders?

app.get("/api/orders", async (_req, res) => {
  const orderData = await shopify.api.rest.Order.all({
    session: res.locals.shopify.session,
    status: "any",
  });
  res.status(200).send(orderData);
});

 

Looking for a Shopify App developer? Please visit: https://github.com/remy727