How SharePoint Works Before Creating News Post Site Page

In this post, we are going to explore how SharePoint Online works when creating a news post site page. By default, the Site Pages library has a hidden field called Promoted State. This will define whether the modern site page is normal or a promoted news post page.
 
The Promoted State helps SharePoint to identify which type the Site Page belongs to because both the modern site page and news post page use the same content type. So, SharePoint only has the option to categorize based on the Promoted State field. Below are different values allowed for this column,
 
Promoted State
Remarks
0
Normal Site Page
1
The draft version of the News Site Page. Not Published yet.
2
The Published version of the News Site Page
 
WebPart Page or Wiki Page or Default Home Page
 
Before SharePoint creates the news post, it will check whether the current user and current site have the required provision to create a news post site page. To do that, SharePoint uses the below REST API format,
 
https://domain.sharepoint.com/sites/name/_api/sitepages/cancreatepromotedpage
 
Once the above URL returns true, it will redirect the site page creation page and the format for this is as below,
 
https://domain.sharepoint.com/sites/name/_layouts/15/CreateSitePage.aspx?promotedState=1
 
This will create a new modern site page and set the Promoted State as 1. Once the page is saved and published, the Promoted State becomes the News Web part and shows the pages based on the Promoted State in modern pages.
 
Use the below code snippet to verify whether the user and site have the provision to create a new Post. And based on that, it will redirect you to page creation. Oetherwise, it will throw an error.
  1. //getRequest method reference  
  2. //https://gist.github.com/ktskumar/a9e9df497673e9fd26ead8532b9ff425  
  3. function getRequest(url) {  
  4.     var request = new XMLHttpRequest();  
  5.     return new Promise(function(resolve, reject) {  
  6.         request.onreadystatechange = function() {  
  7.             if (request.readyState !== 4) return;  
  8.             if (request.status >= 200 && request.status < 300) {  
  9.                 resolve(request);  
  10.             } else {  
  11.                 reject({  
  12.                     status: request.status,  
  13.                     statusText: request.statusText  
  14.                 });  
  15.             }  
  16.         };  
  17.   
  18.         request.open('GET', url, true);  
  19.         request.setRequestHeader("Content-Type""application/json;charset=utf-8");  
  20.         request.setRequestHeader("ACCEPT""application/json; odata.metadata=minimal");         
  21.         request.setRequestHeader("ODATA-VERSION""4.0");  
  22.         request.send();  
  23.   
  24.     });  
  25. }  
  26.   
  27.   
  28. //Check whether the current user has permission to create promoted site page  
  29. getRequest("https://domain.sharepoint.com/sites/name/_api/sitepages/cancreatepromotedpage").then(function(output) {  
  30.     var cancreatepage = JSON.parse(output.response);      
  31.     if (cancreatepage) {  
  32.         window.location.href = "https://domain.sharepoint.com/sites/name/_layouts/15/CreateSitePage.aspx?promotedState=1";  
  33.     } else {  
  34.         alert("You didn't have permission to create promotes news post site page");  
  35.     }  
  36. });  
  37.   
  38. //Author: Shantha Kumar T  
  39. //Github Source: https://gist.github.com/ktskumar/bc6a36c94cc7965dcfcea5eb7cfda99d