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)

Verxs
Shopify Partner
3 0 0

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

 

Replies 3 (3)

ReturnPrime
Shopify Partner
486 67 111

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

Meltin-Bit
Shopify Partner
27 0 10

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

I've the same exact problem.

thanks in advance.

F.

Meltin Bit
Verxs
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. 😞