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

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

DoWomenFart
New Member
4 0 0

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.

 

Replies 6 (6)

Vellir
Shopify Partner
146 32 40

Can you provide the code snippet you're using?

- Looking for a Wishlist? Try First Wish

- Shopify Merchants, manage your new arrivals with Newr

- Shopify Developers, if you're looking into selling your app to focus on other projects, drop me a line.
DoWomenFart
New Member
4 0 0

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));
Vellir
Shopify Partner
146 32 40

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?

 

 

- Looking for a Wishlist? Try First Wish

- Shopify Merchants, manage your new arrivals with Newr

- Shopify Developers, if you're looking into selling your app to focus on other projects, drop me a line.
DoWomenFart
New Member
4 0 0

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.
Arkadi
Tourist
4 0 4

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));

 

PinalS
Shopify Partner
3 0 4

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,