Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi,
I created a Node.js app using the sample-node-app with Shopify CLI. I created an extension on the more actions drop down of the order page, I can get the order IDs, however when I receive the call I would like to run a few Graphql queries based on the orders I get from the extension call. Although I do not receive a session token and I cannot use Shopify.Utils.loadCurrentSession to get the access token.
app.get("/extension/orders/bulk", async (req, res) => {
console.log(req.query);
// Outputs
// {
// ┃ hmac: '111a4...',
// ┃ host: 'dGVz...',
// ┃ ids: ['4381574332601', '4381574070457', '4381573873849'],
// ┃ locale: 'en-CA',
// ┃ session:'2a1f891...',
// ┃ shop: 'tester12auth.myshopify.com',
// ┃ timestamp: '1650849240'
// ┃
// }
res.redirect(`/?shop=${req.query.shop}&host=${req.query.host}`);
const session = await Shopify.Utils.loadCurrentSession(req, res, true);
console.log(session); // Undefined
})
How can I load the current session or get the access token to be able to use the Graphql API?
Thanks
Hello, at first you have to store the access_token in your database as soon as a store installs your Shopify app. Then you get the token from your DB and proceed with the GraphQL API.
Regards,
Mritunjay
ReturnPrime
Hi, did you solve the undefined session after calling loadCurrentSession?
I've the same exact problem.
thanks in advance.
F.
It looks like ReturnPrime was right. We would need to store the access_token or maybe use offline access. I don't think using loadCurrentSession is possible ( I could be wrong). I suggest trying loadOfflineSession, generating long-term access tokens, and storing them in a database. I haven't been able to try the solution, but if you do, let us know if it works. If this is the only way it works that will be very sad as it would make building extensions way more complicated than I feel it should be. 😞
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024