Liquid, JavaScript, themes, sales channels
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. 😞
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024