Ad

Shopify-api-node Returns Status 401 Unauthorized For Private App

I am attempting to make a NodeJS application utilizing this npm package called shopify-node-api

Please note, this is a private app which was generated in the Shopify Partners account. I've passed the shopName, apiKey and password as instructed by the documentation.

    const Shopify = require('shopify-api-node');

    const shopify = new Shopify({
      shopName: 'your-shop-name',
      apiKey: 'your-api-key',
      password: 'your-app-password'
    });

However, when attempting to perform something as straightforward as this GET:

    shopify.product.get()
    .then(products =>  res.send(products))
    .catch(err => res.send(err));

I receive:

    {
        "name": "HTTPError",
        "hostname": "your-shop-name",
        "method": "GET",
        "path": "/admin/products.json",
        "protocol": "https:",
        "statusCode": 401,
        "statusMessage": "Unauthorized",
        "headers": {...}
    }

To all the Shopify App/JavaScript specialists, please advise on what I am overlooking?

Ad

Answer

At the end of the day my mistake here was an incorrect use of the API call from using these bindings.

Instead of:

 shopify.product.get()
.then(products =>  res.send(products))
.catch(err => res.send(err));

I should have been using this:

shopify.product.list()
.then(products =>  res.send(products))
.catch(err => res.send(err));
Ad
source: stackoverflow.com
Ad