How fetch “webParts” from site pages

2019-08-20 12:24发布

问题:

I am trying to fetch Pages from Sharepoint sites using graph API. But when we make GET request with

https://graph.microsoft.com/beta/sites/{site-id}/pages/{page-id}

the response consists of webParts which only have type and data. Inside data we have an id(which same as type) and an instanceId that is unique for every webPart.

Sample webPart:

{
   "type": "d1d91016-032f-456d-98a4-721247c305e8",
   "data": {
             "id": "d1d91016-032f-456d-98a4-721247c305e8",
             "instanceId": "c54a74ef-86c1-44aa-9ba4-802e6841e3a7"
}

My goal is to fetch webPages with complete details and then backup them to a local drive in any format.

The documentation of graph API shows that the responce would consist of complete details for the webPart, but it is not so. Documentation link: https://docs.microsoft.com/en-us/graph/api/sitepage-get?view=graph-rest-beta&tabs=http

Sample request URL: https://graph.microsoft.com/beta/sites/m365x214355.sharepoint.com,c1e5444e-12d8-43d3-96b1-f2f66559ef58,b181bdf0-9680-4988-81f7-a24aee4afd6a/pages

Webpart repsonse:

"webParts": [
                {
                    "type": "rte",
                    "data": {
                        "innerHTML": "<p>Take a look at the team behind delivering amazing fashion events for Contoso.</p><p>Find out how the team uses the latest technology to plan amazing fashion shows and gather customer feedback for future events.</p><p>Meet the people behind Contoso's events, learn how to plan your own event, and find the necessary resources to run highly successful fashion shows, premiers, and extravaganzas!</p>"
                    }
                },
                {
                    "type": "d1d91016-032f-456d-98a4-721247c305e8",
                    "data": {
                        "id": "d1d91016-032f-456d-98a4-721247c305e8",
                        "instanceId": "c54a74ef-86c1-44aa-9ba4-802e6841e3a7"
                    }
                },
                {
                    "type": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
                    "data": {
                        "id": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
                        "instanceId": "75ccfeba-ad6c-416d-a859-4a6b114e156e"
                    }
                },
                {
                    "type": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
                    "data": {
                        "id": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d",
                        "instanceId": "f04e02fb-45e6-4e74-9f46-0c8d90e7fb8d"
                    }
                },
                {
                    "type": "275c0095-a77e-4f6d-a2a0-6a7626911518",
                    "data": {
                        "id": "275c0095-a77e-4f6d-a2a0-6a7626911518",
                        "instanceId": "c1a222b0-624e-4e30-b544-d2a67e8e1112"
                    }
                }

Expected Response format:

"webParts": [
        {
            "type": "rte",
            "data": {
                "innerHTML": "<p>Here are the team's upcoming events:</p>"
            }
        },
        {
            "type": "d1d91016-032f-456d-98a4-721247c305e8",
            "data": {
                "title": "Events",
                "description": "Display upcoming events",
                "serverProcessedContent": {
                    "htmlStrings": {},
                    "searchablePlainTexts": {
                        "title": ""
                    },
                    "imageSources": {},
                    "links": {
                        "baseUrl": "https://www.contoso.com/sites/Engineering"
                    },
                    "componentDependencies": {
                        "layoutComponentId": "8ac0c53c-e8d0-4e3e-87d0-7449eb0d4027"
                    }
                },
                "dataVersion": "1.0",
                "properties": {
                    "selectedListId": "032e08ab-89b0-4d8f-bc10-73094233615c",
                    "selectedCategory": "",
                    "dateRangeOption": 0,
                    "startDate": "",
                    "endDate": "",
                    "isOnSeeAllPage": false,
                    "layoutId": "FilmStrip",
                    "dataProviderId": "Event",
                    "webId": "0764c419-1ecc-4126-ba32-0c25ae0fffe8",
                    "siteId": "6b4ffc7a-cfc2-4a76-903a-1cc3686dee23"
                }
            }
        }
    ]

I want webParts in the format as per documentation. If the instanceId is unique then there might be some reference table to match these instanceIds and fetch the detailed webParts structure.