sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Is it possible to create a page based on a custom template using the Graph API?

Open roberAlb opened this issue 1 year ago • 4 comments

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

  • [ ] 💥 Internet Explorer
  • [X] 💥 Microsoft Edge
  • [X] 💥 Google Chrome
  • [ ] 💥 FireFox
  • [ ] 💥 Safari
  • [ ] mobile (iOS/iPadOS)
  • [ ] mobile (Android)
  • [ ] not applicable
  • [ ] other (enter in the "Additional environment details" area below)

Additional environment details

No response

Issue description

Basically we were exploring Graph API to create SP pages but our scenario are based on custom template created by us, so we wanted to clarify is there is a way to create a page based on a custom template. We didn't see anything as part of the documentation and we would like to know if this is in the roadmap or not. Thanks.

roberAlb avatar Apr 23 '24 10:04 roberAlb

Hi @roberAlb! It seems that currently, there's no straightforward method available in the pages API. However, you can achieve the same effect by following this procedure:

  1. Retrieve the template item unique ID to use in the pages API. A template is actually the page located in the Template folder. You can do this using the following endpoint: https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/items/{itemListId}?$select=contentType,sharepointIds Make sure to get the sharepointIds.listItemUniqueId for the next step.
  2. Obtain the page content of the template. Note that page templates are not included in the list of pages using https://graph.microsoft.com/v1.0/sites/{SiteId}/pages endpoint, but you can still access them directly: https://graph.microsoft.com/v1.0/sites/{SiteId}/pages/{listItemUniqueId}/microsoft.graph.sitePage?$expand=canvasLayout
  3. Extract the canvasLayout object from the result and remove properties such as [email protected], [email protected], [email protected].
  4. Make a POST call to https://graph.microsoft.com/v1.0/sites/{siteId}/pages with the edited canvasLayout parameter and all required fields in the body.

Let me know if that works for you.

mkm17 avatar Apr 24 '24 08:04 mkm17

Hi @mkm17 thanks for your message,

but I don't think it's going to work, bacause the page template contains some custom webparts and they are not allowed as far as I'm reading.

roberAlb avatar Apr 24 '24 11:04 roberAlb

Hi @roberAlb I quickly tested the same method with my custom SPFx web part, and it successfully created a new page with non-standard Microsoft web parts.

mkm17 avatar Apr 24 '24 12:04 mkm17

Hi @mkm17 again,

I was making some tests and looks like is working, it was giving me just an error about an OOTB Yammer web that is not supported, but after removing it, the request worked, Thanks!!

However there is an important point for us as well here, which is the content type, the template has a content type assigned but it's not coming when trying to get it as I cannot see any property to specify it.

Thanks again,

roberAlb avatar Apr 25 '24 06:04 roberAlb

Hello @roberAlb, Thank you for bringing this issue to our attention. Could you please confirm if the issue still persists for you?

Amey-MSFT avatar May 23 '25 06:05 Amey-MSFT

We are closing this issue for now. If the problem persists, feel free to reopen it or open a new one.

Amey-MSFT avatar Jul 07 '25 10:07 Amey-MSFT