Happening now | Office Hours: Customizing Your Theme With Moeed | Ask your questions now!
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

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

Solved

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

Wakil_eFoli
Shopify Partner
47 2 6

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
437 55 80

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 Email Me Buy Me A Coffee

View solution in original post

Replies 2 (2)

Wakil_eFoli
Shopify Partner
47 2 6

This is what I get in the browsers console

Wakil_eFoli_0-1712217496806.png

 

Kyle_liu
Shopify Partner
437 55 80

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 Email Me Buy Me A Coffee