0

I need to retrieve the webpart title on a page via graph.

I can use this uri below

Which lists all webparts on the page

GET /sites/{site-id}/pages/{page-id}/microsoft.graph.sitePage/webParts/{webpart-id}

https://graph.microsoft.com/v1.0/sites/46f7d5ae-0c5e-4711-9910-8898e141c29b/pages/2e339472-1401-46b8-9765-0d2425e2f7e3/microsoft.graph.sitePage/webParts?$select=*

My output

   "@odata.type": "#microsoft.graph.standardWebPart",
            "id": "5f55379d-04cd-4277-99f9-33b52040944f",
            "webPartType": "cbe7b0a9-3504-44dd-a3a3-0e5cacd07788",
            "data": {
                "dataVersion": "1.6",
                "description": "Show a banner with title and author information",
                "title": "Banner",

How do i navigate to get the title Banner? Thanks

2
  • Are you using C# SDK or TypeScript code? Commented Feb 24 at 12:48
  • Hi Dikesh, Sorry i didn't mention it. Its via Power Automate Commented Feb 26 at 3:45

1 Answer 1

0

If you are using TypeScript code, then you can try below code.

.......
.then(response => response.json())
.then(data => {
    const titles = data.value.map(webPart => webPart.data.title);
    console.log(titles);
})
.catch(error => console.error('Error:', error));

As far as I know direct attribute/property is not available that simply extract the Title for now.


In Power Automate:

I believe you are aware about how to call the graph API in Power Automate using HTTP action.

(If not, here is one reference: https://www.csharp.com/article/calling-graph-api-from-power-automate-flow/)

Steps to extract Web part titles:

  • Using Parse JSON action, you can convert your body output into JSON object. Use below schema in Parse JSON action:

    {
        "type": "object",
        "properties": {
            "@@odata.context": {
                "type": "string"
            },
            "@@microsoft.graph.tips": {
                "type": "string"
            },
            "value": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "@@odata.type": {
                            "type": "string"
                        },
                        "id": {
                            "type": "string"
                        },
                        "webPartType": {
                            "type": "string"
                        },
                        "data": {
                            "type": "object",
                            "properties": {
                                "dataVersion": {
                                    "type": "string"
                                },
                                "description": {
                                    "type": "string"
                                },
                                "title": {
                                    "type": "string"
                                },
                                "properties": {
                                    "type": "object",
                                    "properties": {
                                        "description": {
                                            "type": "string"
                                        }
                                    }
                                },
                                "serverProcessedContent": {
                                    "type": "object",
                                    "properties": {
                                        "htmlStrings": {
                                            "type": "array"
                                        },
                                        "searchablePlainTexts": {
                                            "type": "array"
                                        },
                                        "links": {
                                            "type": "array"
                                        },
                                        "imageSources": {
                                            "type": "array"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "required": [
                        "@@odata.type",
                        "id",
                        "webPartType",
                        "data"
                    ]
                }
            }
        }
    } [![enter image description here][1]][1]
    

    Content: @{body('HTTP')}

    Schema: above provided JSON

  • Next, you add one loop, and compose under that loop to extract and traverse through all the web part titles.

    enter image description here

    Select an output from previous steps: @{body('Parse_JSON')?['value']}

    Inputs: @{items('Apply_to_each')?['data']?['title']}

My output: I have 7 web parts added on the page. And I see 7 iterations in Apply to each and web part title in compose action. enter image description here

2
  • Thanks Dikesh.Sorry i didn't mention it. Its via Power Automate Commented Feb 26 at 23:07
  • @naijacoder: I have updated my answer for the power automate solution. Commented Mar 3 at 13:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.