I am using the SharePoint REST API to automate the site creation process. I have created a Python script that calls the SharePoint Online REST API via the following endpoint:
https://{tenant}.sharepoint.com}/_api/SPSiteManager/create
This creates a site within https:/{tenant}.sharepoint.com/sites/.
My issue is that when I create multiple sites using the same method, the web root ID of the created sites are identical--so there is no way to uniquely identify the site. I got this confirmed by using the following endpoint with each site URL:
https://{tenant}.sharepoint.com/sites/{site_name}/_api/web/id
However, the site collection ID on the same sites are different. I got this confirmed using the following endpoint with each site URL:
https://{tenant}.sharepoint.com/sites/{site_name}/_api/site/id
Based on Microsoft's documentation given here, the SharePoint object model is structured in a way that the site collection holds sites within it.
This means that one site collection can have multiple sites and therefore, the site collection ID can be common across multiple sites, but the web root ID (individual site's ID) should be unique.
In my issue, as mentioned earlier, I am receiving multiple site collection IDs and a common web root ID when they are created using the SharePoint Online REST API.
Additional information:
Here's the JSON payload in the request:
payload = {
"request": {
"Title": {site_title},
"Url": f"https://{tenant_name}.sharepoint.com/sites/{site_name}",
"Lcid": 1033,
"ShareByEmailEnabled": False,
"WebTemplate": "STS#3",
"SiteDesignId": "00000000-0000-0000-0000-000000000000",
"Owner": {site_owner},
}
}
I am using SharePoint Online REST API, not Microsoft Graph.
Authentication is based on app-only token as I need to have the process running without human intervention.
I have tried the following options with no change in result:
- Changing the endpoint to the SharePoint Admin URL:
https://{tenant}-admin.sharepoint.com/_api/SPSiteManager/create
- Authentication with direct SPO token instead of the certificate based approach
Has anyone experienced this issue before? How should I change the approach to create sites with unique web root IDs and a common site collection ID?
Any help/guidance is really appreciated.