Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 of 9 tasks
roberAlb opened this issue Apr 23, 2024 · 4 comments
Open
2 of 9 tasks

Comments

@roberAlb
Copy link

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
  • 馃挜 Microsoft Edge
  • 馃挜 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.

@mkm17
Copy link

mkm17 commented Apr 24, 2024

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 horizontalSections@odata.context, columns@odata.context, webparts@odata.context.
  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.

@roberAlb
Copy link
Author

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.

@mkm17
Copy link

mkm17 commented Apr 24, 2024

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.

@roberAlb
Copy link
Author

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants