MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
947 stars 278 forks source link

Unable to make any calls with the API - Always getting HTML in the body #627

Closed ozzyonfire closed 8 months ago

ozzyonfire commented 1 year ago

I'm really confused as to what's going on.

Upgraded a bunch of packages, including this one to the latest version.

trying to just perform a simple test with the API results in the body coming back as my site's homepage HTML.

For example;

  try {
    const api = new ShopifyAPI({
      accessToken: shopify_us.devAccessToken,
      shopName: shopify_us.shopName,
      apiVersion: '2022-04',
    });

    const shop = await api.shop.get({});
    console.log(shop);
  } catch (err) {
    const error = err as any;
    console.log(error.request);
  }

This gives me an error saying it was unable to parse the json. Unexpected token <. I went through the error and found the headers, and the url. Everything looks okay.

_header: 'GET / HTTP/1.1\r\n' +
        'user-agent: shopify-api-node/3.12.6\r\n' +
        'x-shopify-access-token: shpat_-----------------------\r\n' +
        'accept: application/json\r\n' +
        'accept-encoding: gzip, deflate, br\r\n' +
        'Host: ecstasy-crafts.myshopify.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
...
      url: 'https://ecstasy-crafts.myshopify.com/admin/api/2022-04/shop.json?',
      statusCode: 200,
      statusMessage: 'OK',

However if I just run the following simple axios request, everything works as expected.

const response = await axios.get(`https://${shopify_us.shopName}.myshopify.com/admin/api/2022-04/shop.json`, {
  headers: {
    'X-Shopify-Access-Token': shopify_us.devAccessToken,
    'Content-Type': 'application/json',
  }
});

I'm wondering if GOT is doing something funky with the redirects or something is happening under the hood. I'm going to start a fresh project and see if I can figure out what happened.

Any ideas?

lpinca commented 8 months ago

I'm closing this as I can't reproduce the issue.

ozzyonfire commented 8 months ago

I believe there was a conflict with some packages - I was able to fix this with a fresh install. Sorry, meant to circle back on this.