Create a headless Node.js custom app

I am learning Shopify app development, and I got my first gig from a friend!

In short, I need to make an app that on a regular schedule, would access an FTP server and download a list containing product SKU to which I should update the quantity, then using the GraphQL API I would update the products I need.

Currently, I created a Node.js app using the Shopify-CLI.

So far so good, however, I am not sure about a few parts of this app:

  • Since I need to schedule operations using something like this https://www.npmjs.com/package/node-cron how can I authenticate every time my ApolloClient? ApolloClient, to instantiate needs shop and accessToken, which normally come from the request cookie, however in my case, “I should have them available any moment” in order to run my logic on schedule.

  • I found a very well written documentation regarding the Node.js + React part, however, I am missing something regarding the backend logic. Where can I find more documentation regarding my use case?

  • The CLI creates already backend code to instantiate the client:

export const createClient = (shop, accessToken) => {
  return new ApolloClient({
    uri: `https://${shop}/admin/api/2019-10/graphql.json`,
    request: (operation) => {
      operation.setContext({
        headers: {
          "X-Shopify-Access-Token": accessToken,
          "User-Agent": `shopify-app-node ${process.env.npm_package_version} | Shopify App CLI`,
        },
      });
    },
  });
};

Hence, it seems to me that this use case has already been tackled somehow. However, I have some troubles understand how can I leverage this boilerplate code in my case.

  • There might be a chance this is not a good use case of the Shopify CLI, and my approach is completely wrong. What do you suggest would be a better approach for this app?

Sorry for the long post, and thanks in advance anyone :slightly_smiling_face:

I am having the same struggle with a custom application. I am attempting to make a request to the GraphQl Admin API via a headless back-end application running at a scheduled interval. I have had success in requesting an access token and using that, but its only valid for 24 hours. once the token expires, a request to the auth route in the boilerplate app must be manually navigated to in a browser, where a user is authenticated to the proper Shopify Store. This is a kludgy work around at best. Is there an undocumented oAuth flow available? Or does this use case validate the need for Private apps?

Hello guys,

I have exactly the same use case. Did you manage to get some progress with your approach?

Are you using the Storefront token ? that should not expire