I’m trying to create Page using these two following approaches but none of them seems to work but I can make other GET and POST request from my app like I can create and fetch products using Rest API.
So, I took these 2 following approaches to create Page(Documentation)
Approach 01:
// Creating Page
const pageCreateReq = await admin.rest.post({
path: "pages",
data: {
page: {
title: "Contact us",
handle: "contact-us",
template_suffix: "contact",
author: "Lydia",
body_html: "Contact us at <a href='mailto:contact@johns-apparel.com'>contact@johns-apparel.com</a>."
},
},
});
const pageCreateRes = await pageCreateReq.json();
console.log(pageCreateRes);
return json(pageCreateRes);
Result of Approach 01: This returns [object Object] in the app’s iFrame but the console log in the apps console or web’s console gives nothing.
Approach 02:
const page = new admin.rest.resources.Page({session: session});
page.title = "Warranty information";
page.body_html = "<h2>Warranty</h2>\n<p>Returns accepted if we receive items <strong>30 days after purchase</strong>.</p>";
const pageCreateReq = await page.save({
update: true,
});
const pageCreateRes = await pageCreateReq.json();
console.log(pageCreateRes);
return json(pageCreateRes);
Result of Approach 02: Prints following in the console.
POST https://exmaple.trycloudflare.com/app/app-name-app.myshopify.com×tamp=1712144263&_data=routes%2Fapp.create-cards 403 (Forbidden)