How to get Authorization for creating a page using Sharepoint rest api without Azure AD and username-authentication

Chethan R 0 Reputation points
2023-10-10T05:53:46.1066667+00:00

This is the code I am trying to execute :-

import fetch from 'node-fetch';

const siteUrl = 'url'; 
const libraryName = 'Pages';  
const pageData = {   
'__metadata': { 'type': 'SP.Publishing.ReusableHTMLItem' },   'Title': 'New Page Title',   'LayoutWebpartsContent': '<div>Page Content Goes Here</div>',   'Publish': true 
};

const headers = {   
'Accept': 'application/json;odata=verbose',   
'Content-Type': 'application/json;odata=verbose',   'Authorization': 'Access Token' 
};

fetch(`${siteUrl}/_api/web/lists/getbytitle('${libraryName}')/AddValidateUpdateItemUsingPath()`, 
{   
method: 'POST',   
headers: headers,   
body: JSON.stringify(pageData) 
}) 
.then(response => {   
if (response.status === 201) {     
console.log('Page created successfully.');   
} else {     
console.error('Page creation failed.');   
} }) 
.catch(error => {   
console.error('Error:', error); 
});

Need a way to get the Access token for the Authorization for header without Azure AD or Username and password.

Or Else need another way to create a page in a SharePoint using Rest API without Azure AD or Username and password.

Or Else please provide the link or documentation Which says It's not possible to get Authorization for header without Azure AD or Username and password.

Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Microsoft 365 and Office | SharePoint | Development
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-10-11T02:31:54.8833333+00:00

    Hi @Chethan R,

    Instead of AAD application, you could use OAuth 2.0 and OpenID Connect in the Microsoft identity platform.

    You could refer to the following document to register the access

    https://learn.microsoft.com/en-us/graph/auth-v2-service?tabs=http


    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.


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.