Ad

Shopify - Private App, 401 Unauthorized (Javascript)

- 1 answer

Since yesterday I try to juste get a list of my products via Shopify Javascript API.

1. Shopify Javascript API
I tried to follow this tutorial: https://shopify.github.io/js-buy-sdk/
My code:

const shopClient = ShopifyBuy.buildClient({
  apiKey: 'e1616e793836bd1178d34dfa124667cf',
  appId: '6',
  domain: 'cordillot-store.myshopify.com'
})

// fetch a product using resource id
shopClient.fetchAllProducts()
  .then(function (product) {
    console.log(product)
  })
  .catch(function () {
    console.log('Request failed')
  })


And I got a 403: 403

2. Private App instructions
So, I decided to follow the instruction after creating my private app enter image description here
My code:

import request from 'superagent'

request
  .get('https://e1616e793836bd1178d34dfa124667cf:[email protected]/admin/products.json')
  .end((error, response) => {
    console.log(error)
    console.log(response)
  })

And I got a 401: enter image description here
But, this URL works well with cURL

curl -X GET https://e1616e793836bd1178d34dfa124667cf:[email protected]/admin/products.json

3. Public App After I created a Public Application and try to connect with Oauth (https://help.shopify.com/api/guides/authentication/oauth).
Everything runs good until I tried to reach the URL 'http://[SHOP_NAME]/admin/oauth/access_token', I got an 404.

Anyone can help me?

Thank you a lot!

Ad

Answer

Hi i tried shopify javascript sdk https://shopify.github.io/js-buy-sdk/ . getting same error because of Permission in admin app. Follow the below steps fix that issue.

1) Login into shop admin page 2) Add Sales Channels as Buy Button. 3)Choose Buy Button in side menu and create new JavaScript Buy SDK token then try create token

4) Then try your code Example Code

const shopClient = ShopifyBuy.buildClient({
  accessToken: '1c51f10dc2a3bd1e7dc31974cdc06aef',
  appId: '6',
  domain: 'shopify-deals-dev.myshopify.com'
});

shopClient.fetchAllProducts()
  .then(function (product) {
    console.log(product);
  })
  .catch(function () {
    console.log('Request failed');
  });
Ad
source: stackoverflow.com
Ad