WebPart Title not showing when added with Graph API

Giuseppe Fusco 0 Reputation points
2025-01-14T08:30:34.2766667+00:00

Hello,

I am experiencing an issue with WebPart titles in SharePoint Online. Specifically:

When I add WebParts to a SharePoint page using the Microsoft Graph API, everything works as expected initially.

However, when the page is viewed in desktop mode, the WebPart titles do not appear. Upon inspecting the HTML, I noticed that the <span> element intended to contain the title is generated but remains empty:

   <span role="heading" aria-level="2" id="CaptionElementView" data-automation-id="webPartTitleReadMode" style="cursor: text;"></span>

When the same page is viewed on mobile devices, or in a browser using mobile emulation, the WebPart titles are correctly populated.

The corresponding HTML in mobile mode is as follows:

   <span role="heading" aria-level="2" id="CaptionElementView" data-automation-id="webPartTitleReadMode" style="cursor: text;">Document Tracker</span>

I believe this is a bug in the rendering of WebParts in desktop mode. It seems that the title information is either not passed correctly or not rendered in the desktop view.

Steps to Reproduce

  1. Use Microsoft Graph API to add a WebPart (e.g., a List WebPart) to a SharePoint page.

here is the C# code i use:

var listWebPartRequest = new Microsoft.Graph.Beta.Models.StandardWebPart {
    OdataType = "#microsoft.graph.standardWebPart",
    WebPartType = "f92bf067-bc19-489e-a556-7fe95f508720",
    Data = new Microsoft.Graph.Beta.Models.WebPartData {
        Title = "Document Tracker",
        Properties = new Microsoft.Graph.Beta.Models.Json {
            AdditionalData = new Dictionary<string, object>
        {
            { "selectedListId", documentTrackerList.Id },
            { "selectedListUrl", relativeSiteUrl + "/Document Tracker" },
            { "webRelativeListUrl", "/Lists/Document Tracker" },
            { "webpartHeightKey", "4" }
        }
        },
        DataVersion = "1.0"
    }
};

var listWebPartResult = await betaClient.Sites[projectSite.Id].Pages[homePage.Id].GraphSitePage.CanvasLayout.HorizontalSections["3"].Columns["1"].Webparts.PostAsync(listWebPartRequest);
  1. Open the page in a desktop browser and observe that the WebPart title is missing.
  2. Open the same page on a mobile device or use mobile emulation in the browser. The title will be correctly displayed.

Am I doing something wrong?

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,192 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 48,906 Reputation points Microsoft Vendor
    2025-01-15T02:59:39.81+00:00

    The title may need to be declared in Properties.AdditionalData. You can try to add another web part title in the C# codes.

    AdditionalData = new Dictionary<string, object> 
    { 
      { "selectedListId", documentTrackerList.Id }, 
      { "selectedListUrl", relativeSiteUrl + "/Document Tracker" }, 
      { "webRelativeListUrl", "/Lists/Document Tracker" }, 
      { "webpartHeightKey", "4" }, 
      { "webPartTitle", "Document Tracker" } // Add this field 
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.