[Tutorial & Example] Create a SharePoint site using REST API

Do you know that you can very easily create a SharePoint site using REST API call? If not, do not worry this post is all about that.

sharepoint-icon-x128

Pre-requisites

You need to have SharePoint license and a method to call API. For this example I am using Power Automate, so if you have Power Automate you can follow along. Anyhow, you may use any application of your choice.

The benefit of using Power Automate is that I do not need to send authentication header while calling the API. However if you are using any other application, make sure that you have authorization token to authenticate your API call.

If you are not aware of Power Automate or just starting to use it, I recommend you to check my beginner friendly tutorials first
What is Microsoft Power Automate? – Beginner’s Guide
How to Start using SharePoint API

Tutorial

First Method – Create Sub-site

#1. Create an “Instant” Power Automate Flow

Navigate to flow.microsoft.com

Then choose My flows > New Flow > Instant Cloud Flow(to manually trigger the flow). Then give it a name, choose manual trigger and click create to finish creating the flow.

create an instant cloud flow newbietechine
Instant cloud flow
create a sharepoint site using rest api power autmate flow

#2. Once the flow is created add an action for HTTP request

Click on new step (below the first block). Search for Send an http request to SharePoint and add the block

Power Automate flow to create a SharePoint Online Site
Add the block

#3. Add the HTTP request details

The only problem with this API call(Uri) is that it cannot create a site collection instead can only create a sub-site. So if you need to create a site collection then follow the alternate method below.

Use the send http request to SharePoint block to send a POST request for creating the site. The details of the HTTP call is as below

power automate POST rest API call to create site
HTTP post method

Site address – You can use a site collection address or subsite address, anything is fine.

Method – As we are creating a site, we need to use the POST method.

Uri – _api/web/webinfos/add

Body – The details passed in the body are the required parameters to create a site. If you do not pass those information then site may not be created correctly. The details of different properties are
Url – URL/Link of the site
Language – 1033 means english. If you want any other language, check REST API to change site language
WebTemplate – sts, means the site will have modern home page. If you need classic homepage then use sts#0
Apart from the above, you can use other parameters as well. Those are not mentioned to keep the tutorial simple.

{'parameters': {
            '__metadata':  {'type': 'SP.WebInfoCreationInformation' },
            'Url': 'APISite',
            'Title': 'API Created Site',
            'Description': 'Site Created by REST API',
            'Language':1033,
            'WebTemplate':'sts',
            'UseUniquePermissions':false}
        }

A brain-friendly guide for Beginners!

Microsoft 365 and SharePoint Online Cookbook
Over 100 actionable recipes to help you perform everyday tasks effectively

Amazon Links:

Amazon India, Amazon US, Amazon UK

Once you run the flow or call the API with the details, you should see the site created.

sub site created by REST API Power Automate

Become Financially Independent!

Amazon Links:

Amazon India, Amazon US

Rich Dad & Poor Dad
Know what the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!

Alternate method – Site Collection

As mentioned, the earlier method can only create a subsite and hence it may not serve your requirement completely. If you need to create a site collection, then follow this method instead.

site collection created by REST API from Power Automate

As you can it is different from the previous one. Site address, Uri, Body everything is different from the before one.

Uri – _api/SPSiteManager/create

Body

{
  "request": {
    "Title": "Communication Site 1",
    "Url":"https://wtechworld.sharepoint.com/sites/commsite1",
    "Lcid": 1033,
    "ShareByEmailEnabled":false,
    "Classification":"Low Business Impact",
    "Description":"Description",
    "WebTemplate":"SITEPAGEPUBLISHING#0",
    "Owner":"NurulH@wtechworld.onmicrosoft.com"
  }
}

The result site should look as below. The items marked in red in the below image are for highlighting the information passed in the API call.

site collection created by Rest API call from Power Automate successfully

Well that’s all for this post. I hope you now have some idea on how to use REST API to create a SharePoint site. However if you have any questions, feel free to ask in the comments section below. Anyways, thank you for reading.

More information can be found in these Microsoft documents

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-rest-endpoints

https://docs.microsoft.com/en-us/sharepoint/dev/apis/site-creation-rest


Newbietechie.com
Author @ramizmollahmd

About Ramiz

Ramiz is a professional working in an MNC as a business and technology consultant for quite a few years now. Ramiz is proficient in various Microsoft tools and technologies. He is a tech enthusiast and an active blogger. Ramiz spends his free time playing games or watching movies. He writes blogs to share his knowledge with the world and to make it a better place to live.


Please Help us Grow!

I hope you have found this article helpful. If you are happy with the document, please use the below links when you buy something from Amazon to help us grow.

Ways to Help

Amazon Affiliate Links

How this works?

Amazon affiliate program gives a small (%)share of price to the referrers, so feel free to buy anything.
Below are some Amazon affiliate links, if you open amazon application/website using these links and buy something, (it can be one of the below items or anything of your choice) Then Amazon will give us a little percentage(%) of the money you spend on Amazon. To know more check this document.

$350-Best Student laptop
Amazon In, Amazon US

$600-Work laptop
Amazon In, Amazon US

$989– High performance
Amazon In, Amazon US

Headset – $15.99
Amazon In, Amazon US

Lightspeed Mouse – $39
Amazon In, Amazon US

Keyboard – $29
Amazon In, Amazon US

The Psychology of Money
Amazon In, Amazon

Atomic Habits:
Amazon In, Amazon

Find Balance and Purpose in Life
Amazon In, Amazon

$30, Smart Watch for Smart you
Amazon In, Amazon US, Amazon UK

Work comfortably with $110
Amazon In, Amazon US, Amazon UK

Exercise at home
Amazon In, Amazon US, Amazon UK

Thank you
For your Contribution

Leave a Comment