Hey there,
we are currently building an Shopify app which includes the functionality to export a list of products. We want to implement this functionality into a separate microservice that will be running on a cronjob inside a separate docker container so that we can put the load off our main app server.
How can we authenticate and access the Shopify GraphQL API using this separate NodeJS service, running independent from the normal Shopify NodeJS app and that will not be accessed from the browser (i.e. can’t use cookies eather)? We can’t seem to find existing documentation on this topic.
We have implemented a custom *Shopify.Session.*CustomSessionStorage that is saving the session data into a redis DB so that our microservice can access them too.
Our microservice is now initializing Shopify with the same env variables
Shopify.Context.initialize({
API_KEY: process.env.SHOPIFY_API_KEY!,
API_SECRET_KEY: process.env.SHOPIFY_API_SECRET!,
SCOPES: process.env.SCOPES!.split(","),
HOST_NAME: process.env.HOST!.replace(/https:\/\//, ""),
API_VERSION: ApiVersion.October21,
IS_EMBEDDED_APP: true,
SESSION_STORAGE: new Shopify.Session.CustomSessionStorage(
sessionStorage.store,
sessionStorage.load,
sessionStorage.destroy
),
});
Looking at the library we tried using “Shopify.Utils.loadOfflineSession” to load the session data from our redis:
const session = await Shopify.Utils.loadOfflineSession(myShopifyDomain);
But session will always return undefined, even when the session is stored in Redis.
Unfortunately, the sessions in the Redis DB also all seem to expire after only a few hours to 1 day - is there a method that allows long-term authentication so our cronjob can run automatically?