skip to Main Content

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?

2

Answers


  1. Chosen as BEST 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));
    

  2. Check the API key to ensure you have given it the scope needed to access products. Failure to ask for read/write scope on products would be a good clue as to 401. That or you are not passing the api key and password as per what is presented to you in the shop.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search