Discuss all the new features introduced with the new product model in GraphQL.
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%2... 403 (Forbidden)
Solved! Go to the solution
This is an accepted solution.
Please check the shopify.app.toml file in the project, add "write_content, read_content" in the scopes, and re run the project
This is what I get in the browsers console
This is an accepted solution.
Please check the shopify.app.toml file in the project, add "write_content, read_content" in the scopes, and re run the project