简体   繁体   中英

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM