node.jsshopify-api-node

Trying to fetch Analytics data from Shopify with nodejs


I'm trying to fetch Analytics data for a website with Nodejs and I am having a hard time. I'm following this tutorial but there is a snag I need an access token and to do that it seems that you need to join a Shopify partner account and then create an app and then generate a link that the shop needs to install in order to get an access token.

All I want to do is access a shop's analytics metrics so that I can use the data somewhere else. Is this the only way or am I doing it wrong (if so please send help)

I have tried this https://github.com/lpinca/shopify-token repo as well to generate the access token for the shop but if I use the access token generated then I get this as response

data returned:
 {
  errors: '[API] Invalid API key or access token (unrecognized login or wrong password)'
}

my code so far


const express = require("express");
const fetch = require("node-fetch");
const ShopifyToken = require('shopify-token');



const app = express();


app.get("/shop-info", (req, res) => {
    fetch(`https://SHOPNAMEHERE.myshopify.com/admin/api/graphql.json`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-Shopify-Access-Token": process.env.ACCESSTOKEN
      },
      body: JSON.stringify({
        query: `{
           shop {
             name
             url
             email
             myshopifyDomain
           }
         }`
      })
    })
      .then(result => {
        return result.json();
      })
      .then(data => {
        console.log("data returned:\n", data);
        res.send(data);
      });
  });

app.listen(3000, () => console.log("Listening on port 3000 .... "));

Solution

  • You can use the shared secret code as the access token that's generated after creating a private app in the store itself instead of going the whole partner account

    NOTE THIS IS only if you need to access ONE STORE if its for multiple then its recommended to use the partner route way