Re: How to access Shopify API from Shopify App Theme app extension

How to access Shopify API from Shopify App Theme app extension

dotamir
Shopify Partner
4 0 0

Hi. I hope you are having a good day.

 

I'm working with app proxies to request Shopify admin API but there is an issue. I can connect to the custom API and receive the response successfully. But when I'm trying to connect Shopify API using custom API, it is not working.

 

I see that the issue is `session` which is undefined when I'm trying to call a request from the Theme extension. So my question is how can I get the session and send it to Shopify API when I'm calling the request from the Theme extension?

Here is my custom API code:

app.get("/products/count", async (_req, res) => {
  console.log('result', res.locals.shopify) // undefined
  const countData = await shopify.api.rest.Product.count({
    session: res.locals.shopify?.session,
  });
  res.status(200).send(countData);
});

And here is the error:

2023-08-03 13:41:55 │ web-backend  │         super({ domain: params.session.shop });
2023-08-03 13:41:55 │ web-backend  │                                        ^
2023-08-03 13:41:55 │ web-backend  │
2023-08-03 13:41:55 │ web-backend  │ TypeError: Cannot read properties of undefined (reading 'shop')

 

Thanks in advance.

Reply 1 (1)

huykon225
Shopify Partner
5 0 0

did you found the solution?