Re: Get Access Token or Session from an App Extension call (Bulk Action Link)

Get Access Token or Session from an App Extension call (Bulk Action Link)

Shopify Partner
3 0 0



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) => {
    // Outputs
    // {
        //   ┃   hmac: '111a4...',
        //   ┃   host: 'dGVz...',
        //   ┃   ids: ['4381574332601', '4381574070457', '4381573873849'],
        //   ┃   locale: 'en-CA',
        //   ┃   session:'2a1f891...',
        //   ┃   shop: '',
        //   ┃   timestamp: '1650849240'
        //   ┃
        // }
        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?




Replies 3 (3)

Shopify Partner
438 63 102

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.





Shopify Partner
26 0 10

Hi, did you solve the undefined session after calling loadCurrentSession? 

I've the same exact problem.

thanks in advance.


Meltin Bit
Shopify Partner
3 0 0

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. 😞