To design a SharePoint communication site using REST API, you need to create an app registration in Azure AD and grant it the necessary permissions to access the SharePoint site. You also need to obtain an access token from Azure AD and use it in the Authorization header of your REST requests. Here are some steps you can follow:
Here is a link for your reference:
https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app
- Go to the Azure portal and sign in with your account.
- Click on Azure Active Directory and then App registrations.
- Click on New registration and enter a name for your app. Choose Accounts in this organizational directory only for the supported account types. Enter the URL of your SharePoint site as the redirect URI and click Register.
- Copy the Application (client) ID and the Directory (tenant) ID from the app overview page. You will need them later.
- Click on API permissions and then Add a permission. Choose SharePoint from the list of APIs and then select Delegated permissions. Check the permissions you need for your app, such as Sites.Read.All or Sites.ReadWrite.All, and click Add permissions.
- Click on Grant admin consent for <your organization> and confirm the consent.
- Click on Certificates & secrets and then New client secret. Enter a description and an expiration date for your secret and click Add. Copy the value of the secret and store it securely. You will need it later.
- Go to your SharePoint site and click on Site settings. Under Site collection administration, click on Site collection app catalog. If you don’t have an app catalog, you can create one by following these instructions.
- Click on Distribute apps for SharePoint and then New. Upload a manifest file for your app that contains the following information:
<?xml version="1.0" encoding="utf-8"?>
<App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest"
Name="Your App Name"
ProductID="{a unique GUID}"
Version="1.0.0.0"
SharePointMinVersion="16.0.0.0">
<Properties>
<Title>Your App Name</Title>
<StartPage>~remoteAppUrl/Pages/Default.aspx?{StandardTokens}</StartPage>
</Properties>
<AppPrincipal>
<RemoteWebApplication ClientId="<your app client ID>" />
</AppPrincipal>
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Read" />
</AppPermissionRequests>
</App>
Replace <your app client ID>
with the application ID you copied earlier. You can also change the scope and right of the app permission request according to your needs.
- Click on Create to upload your app manifest.
- Go back to your SharePoint site and click on Site contents. Under Apps you can add, find your app and click on it. Click on Trust It to grant the app permissions to access your site.
- To obtain an access token from Azure AD, you can use a tool like Postman or write your own code. Here is an example of how to get an access token using Postman:
- Create a new request with the method POST and the URL
https://login.microsoftonline.com/<your tenant ID>/oauth2/v2.0/token
, where<your tenant ID>
is the directory ID you copied earlier.- In the Headers tab, add a key-value pair with
Content-Type
as the key andapplication/x-www-form-urlencoded
as the value.- In the Body tab, choose x-www-form-urlencoded and add the following key-value pairs:
- **`client_id`**: your app client ID - **`scope`**: **`https://<your site domain>/.default`**, where **`<your site domain>`** is the domain of your SharePoint site, such as **`contoso.sharepoint.com`** - **`client_secret`**: your app client secret - **`grant_type`**: **`client_credentials`**
- Click on Send and copy the value of the
access_token
from the response.
- Click on Send and copy the value of the
- In the Body tab, choose x-www-form-urlencoded and add the following key-value pairs:
- In the Headers tab, add a key-value pair with
- Create a new request with the method POST and the URL
- To make REST requests to your SharePoint site, you need to add an Authorization header with the value
Bearer <your access token>
, where<your access token>
is the token you obtained from Azure AD. You also need to add an Accept header with the valueapplication/json;odata=verbose
to get JSON responses from SharePoint. - For example, to create a communication site using REST, you can make a POST request to
https://<your site domain>/_api/SPSiteManager/create
with the following JSON body:
{
"request": {
"Title": "Communication Site 1",
"Url":"https://<your site domain>/sites/commsite1",
"Lcid": 1033,
"ShareByEmailEnabled":false,
"Classification":"Low Business Impact",
"Description":"Description",
"WebTemplate":"SITEPAGEPUBLISHING#0",
"SiteDesignId":"6142d2a0-63a5-4ba0-aede-d9fefca2c767"
}
}
I hope this helps you with your project. If you have any other questions, please let me know.
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs
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.
Best Regards
Cheng Feng