Is it possible to create a page based on a custom template using the Graph API?
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.
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:
- 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.
- 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}/pagesendpoint, but you can still access them directly: https://graph.microsoft.com/v1.0/sites/{SiteId}/pages/{listItemUniqueId}/microsoft.graph.sitePage?$expand=canvasLayout - Extract the canvasLayout object from the result and remove properties such as [email protected], [email protected], [email protected].
- 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.
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.
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.
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,
Hello @roberAlb, Thank you for bringing this issue to our attention. Could you please confirm if the issue still persists for you?
We are closing this issue for now. If the problem persists, feel free to reopen it or open a new one.