Reputation: 1289
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?
Upvotes: 3
Views: 3140
Reputation: 12594
Some strange solution - but that worked for me in case of iOS SDK which was returning the same error.
As per Shopify documentation for configuring GraphQLClient -> Which have signature something like this:
public init(shopDomain: String, apiKey: String, session: URLSession = URLSession(configuration: URLSessionConfiguration.default), locale: Locale? = nil)
i.e. as per their documentation we needs to pass shopDomain and apiKey to initialise it.
But If I was passing those values correctly - it was not working.
After 2 days of searching and trying lots of solution -
I have just tried to pass API Access token in APIKey parameter - and amazingly that worked.
So, It looks like - Shopify team have named it wrong in iOS SDK - their param name must be accessToken instead of apiKey - this is really confusing.
Upvotes: 0
Reputation: 1289
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));
Upvotes: 1
Reputation: 11427
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.
Upvotes: 0