How to post a SharePoint news link programmatically

One of the main features of SharePoint these days is the possibility to create News that are easily available to everyone in the tenant.

News can be created directly on SharePoint manually or can be created as news links. News links create a new post on SharePoint pointing to an external resource like a newspaper or your third-party news service.

SharePoint news link

The idea of creating news links programmatically came to my mind when I was creating an alternative to the default RSS reader on SharePoint.

Finding the API Microsoft is using to create news links was quite easy using the browser developer tools. Everything needed to replicate the same behavior programmatically using the REST API is highlighted in red in the picture below.

SharePoint repost api

The API can be used in a variety of different scenarios and I’ve created a webpart that allows you to test this scenario on your own environment. The project is available on GitHub, if you want to give it a try do the following:

  1. Clone or download the project from here
  2. Type npm install
  3. Run gulp serve to start the project
  4. Open the workbench in one of your site collections
    g. https://constoso.sharepoint.com/_layouts/15/workbench.aspx
  5. Click on the + icon and add the newslink web part
  6. Fill the form with all the required data
    SharePoint news link webpart
  7. Click on Create
  8. Open the Site Collection you’ve indicated in the form and go to site pages, you should have a new page pointing to your news link

Keep in mind that this is just a sample project and the code as no validations, if you want to use it as a starting point make sure you have a look to the function that does the POST to the SharePoint API.

  private postNewsLink(site, title, description, banner, source): void {
    const body: ISPHttpClientOptions = {
      body: `{"BannerImageUrl":"${banner}",
              "Description":"${description}",
              "IsBannerImageUrlExternal":"true",
              "OriginalSourceUrl":"${source}",
              "ShouldSaveAsDraft":false,
              "Title":"${title}"
            }`
    };

    this.context.spHttpClient.post(site + "/_api/sitepages/pages/reposts", SPHttpClient.configurations.v1, body)
      .then((response: SPHttpClientResponse) => {
        response.json().then((responseJSON: JSON) => {
          //parser the response message
          console.log(responseJSON);
        });
      });
  }

This API can be used in different contexts like Power Automate as I end up doing to create my new RSS Reader on SharePoint, you can see that process here.


No comments yet

Leave a Reply


I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.

%d bloggers like this: