Solved

How to create Page using Rest API in Remix app template?

Wakil_eFoli
Shopify Partner
43 2 5

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&timestamp=1712144263&_data=routes%2... 403 (Forbidden)

Accepted Solution (1)

Kyle_liu
Shopify Partner
26 6 7

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

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me on (liushuaicc@shinetechsoftware.com)

View solution in original post

Replies 2 (2)

Wakil_eFoli
Shopify Partner
43 2 5

This is what I get in the browsers console

Wakil_eFoli_0-1712217496806.png

 

Kyle_liu
Shopify Partner
26 6 7

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

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me on (liushuaicc@shinetechsoftware.com)