Hello,
I built a custom app and i created a public endpoint /test. I am able to return a partial liquid template by setting the Content-Type to “application/liquid.”
From the front website, i’m able to see the response as an html page and the liquid template seems to be compiled.
The problem arises when I try to retrieve data from the Shopify API to populate the liquid template.
import shopify from "../shopify.js";
export default function applyPublicEndpoints(app) {
app.get("/test", async (req, res) => {
const products = await shopify.api.rest.Product.all();
res.status(200).set("Content-Type", "application/liquid").send(`
{% assign products = ${products} %}
{% render 'product-list-grid',
product_list: products,
%}
`);
});
}
However, I don’t have a valid session through res.locals.shopify.session in public endpoint (https://github.com/Shopify/shopify-app-examples/blob/de37fc771f2f05a03e2b8da07fb4b9772c7dda13/qr-code/node/web/middleware/qr-code-api.js#L66).
Is there any other way to fetch products without session ? Or using another API ? Or i’m wrong about the way apps work.