Discount code returns 401 unauthorized access after upgrading from shopify-api-node v2 to v3

Solved
Highlighted
New Member
2 0 0

Hey everyone,

 

I was updating an app that was using shopify-api-node 2.19 to the latest v3.3. And eventually we ran into an issue where 

shopify.discountCode.lookup({code})

returned this as an error:
Screen Shot 2020-04-03 at 1.08.48 AM.png


After receiving this error, I tried checking our private app to see if any permissions changed. Nothing appeared different and so I tried reverting back to 2.19 and it started working again.

 

Our client was setup like this:

const shopify = require('shopify-api-node')({
  shopName: process.env['SHOPIFY_SHOPNAME'],
  apiKey: process.env['SHOPIFY_APIKEY'],
  password: process.env['SHOPIFY_PASSWORD']
});

What is the difference that is causing discountCode.lookup work on 2.19 as opposed to 3.3?

Thanks!

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 166

This is an accepted solution.

Hey @ATLMTW,

 

I was able to replicate this. The lookup endpoint returns a 303 with the location of the discount code.

 

The HTTP client follows this and username:password is lost. Using `accessToken` instead of `username` and `password` seems to work:

 

const shopify = require('shopify-api-node')({
  shopName: 'your-shop.myshopify.com',
  accessToken: 'api-password-here',
});

const code = 'some-code'
shopify.discountCode.lookup({code}).then(result => console.log(result))

 

1 Like
Highlighted
New Member
2 0 0

@SBD_ you're awesome. Thanks it works!

0 Likes