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
Normal Site Page
The draft version of the News Site Page. Not Published yet.
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,
Once the above URL returns true, it will redirect the site page creation page and the format for this is as below,
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. //  
  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.         };  
  18.'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();  
  24.     });  
  25. }  
  28. //Check whether the current user has permission to create promoted site page  
  29. getRequest("").then(function(output) {  
  30.     var cancreatepage = JSON.parse(output.response);      
  31.     if (cancreatepage) {  
  32.         window.location.href = "";  
  33.     } else {  
  34.         alert("You didn't have permission to create promotes news post site page");  
  35.     }  
  36. });  
  38. //Author: Shantha Kumar T  
  39. //Github Source: