Happening now! Shopify Community AMA: Building a Marketing Budget with 2H Media | Ask your marketing budget questions now!

GraphQl doesn't return a result - get orders for customer

GraphQl doesn't return a result - get orders for customer

szczepan
Shopify Partner
5 0 0

I've written applications in node.js and I'm having trouble getting the result from an orders query.

I use: https://shopify.dev/api/admin-graphql/2022-10/queries/orders

 

In the code I make a query:

  const queryString = `
    query {
        orders(first: 20, query:"customer_id:${customerId} AND updated_at:>${minOrderDate}") {
            edges {
                node {
                    id
                    name
                    createdAt
                    currentSubtotalPriceSet {
                    presentmentMoney {
                        amount
                    }
                    }
                }
            }                  
        }
    }
`;
 
During code execution, it logs the generated query. For example:
query {
orders(first: 20, query:"customer_id:5742413086767 AND updated_at:>2022-06-01") {
edges {
node {
id
name
createdAt
currentSubtotalPriceSet {
presentmentMoney {
amount
}
}
}
}
}
}
 
The answer is an empty orders array.
 
When the same query pastes into the application installed on the store:
Shopify GraphiQL App. The result is returned correctly. Request for help in solving the problem.
 
I use API version: January 2022,
 
I tried to run a custom call from the documentation:
const data = await client.query({
      data: `query {
        orders(first: 10) {
          edges {
            node {
              id
            }
          }
        }
      }`,
    })
    .then((result) => {
      console.log(`${JSON.stringify(result.body.data.orders.edges)}`);
      return result;
    })
    .catch((err) => {
      console.log(JSON.stringify(err));
    });
 
Result: []
 
The customers get implementation works ok and is very similar :
  const customers = await client
    .query({
      data: queryString,
    })
    .then((result) => {
      return result;
    })
    .catch((err) => {
      console.log(err);
    });
  return customers;
}
and query:
  const queryString = `query
  {
    customers(first: 200 ,query: "tag_not:student") {
        edges {
            node {
              id
              displayName
              tags
            }
        }
    }
}
`;
 
 
Replies 0 (0)