Is there a way to get a customer orders? (Shopify API Node.js )

As the title says… I’m trying to get a customer orders. Is there any way to do so with using the shopify api node?

I see a method called orders on the customer but it says “id”. I’ve passed it all the id’s that was returned in the customer object.

Here the link to the documentation.

https://www.npmjs.com/package/shopify-api-node

Thanks.

Can you provide the code snippet you’re using?

Yes I can. What id is being passed in the orders method?

shopify.customer
.orders(id)
.then((orders) => res.status(200).json({msg: orders }))
.catch((err) => console.error(err));

It should be the customer numerical Id (e.g. 419331998712) according to this:

https://github.com/MONEI/Shopify-api-node/blob/master/resources/customer.js#L67

What sort of response are you getting back?

Any customer id I give the method I get back a blank array. But, I know the customer exists. Here’s my customer id (1549978173504) that I get when I do a customer search with this method

shopify.customer
      .search({
        first_name: req.body.searchParam
      })
      .then(search => {
        console.log(search)
        return res.status(200).json({
          msg: search
        })
      })
      .catch(err => {
        return res.status(400).json({
          msg: err
        })
      });

After I run that method above I run this method with the id

shopify.customer
  .orders(1549978173504)
  .then((orders) => res.status(200).json({msg: orders }))
  .catch((err) => console.error(err));

and response from the method above returns a blank array.

what you are lacking is a necessary query paramater status - you need to set it to any so that the response will return all customer’s orders. like so:

shopify.customer
  .orders(1549978173504, { status: 'any' })
  .then((orders) => res.status(200).json({msg: orders }))
  .catch((err) => console.error(err));

Hi,

I’ve tried the code as you suggested, but I still get a 401 Unauthorized Error.

Code:

shopify.customer
        .orders( customer.id, { status: 'any' })
        .then((orders) => res.status(200).json({msg: orders }))
        .catch((err) => console.error(err));

I’m using this in the GDPR webhook

app.post('/customers/data_request', async(req, res) => {});

and customer.id contains the Customer ID for whom data is requested.

Any help is appreciated.

Thanks,