Cannot get latest orders. Cache problem.

Sensationsprint
Visitor
2 0 0

I've tried to fetch orders data by REST admin api or GraphQL api. However, I can not get the latest order when there's a new one established.

 

I believe there's certain cache system block me from getting the latest order data.  Or, is anything I done incorrect? 

 

 

 

 

 

// environment: Node.js v18
// framework: next.js
// server: Vercel 

// REST api
export const fetchShopifyOrders = async () => {
  const url = 'https://example.myshopify.com/admin/api/2023-07/orders.json?status=any';
  const response = await fetch(url, {
    headers: {
      'Content-Type': 'application/json',
      'X-Shopify-Access-Token':
        process.env.NEXT_PUBLIC_SHOPIFY_ACCESS_TOKEN || '',
    },
  });
  const data = await response.json();

  return data;
};


// GraphQL 
export const fetchShopifyOrdersGraphQL = async () => {
  const url = `https://example.myshopify.com/admin/api/2023-07/graphql.json`;
  const response = await fetch(url, {
    headers: {
      'Content-Type': 'application/json',
      'X-Shopify-Access-Token':
        process.env.NEXT_PUBLIC_SHOPIFY_ACCESS_TOKEN || '',
    },
    method: 'POST',
    body: JSON.stringify({
      query: `query { 
        orders(first: 25, query: "", reverse: true, sortKey: CREATED_AT) { 
          nodes { 
            id
            name
            createdAt
            displayFulfillmentStatus
            customAttributes {
              key
              value
            }
            shippingAddress {
              firstName
              lastName
            }
            totalPriceSet {
              shopMoney {
                amount
              }
            }
          }
        }
      }`,
    }),
  });
  const data = await response.json();

  return data;
};

 

 

 

 

 

 

 

Replies 2 (2)

SBD_
Shopify Staff
1829 269 407

Hey @Sensationsprint 

 

Are you able to DM me store details + example missing order?

Scott | Developer Advocate @ Shopify 

Sensationsprint
Visitor
2 0 0

thanks, i've sent message to you. please check it.