Here we will discuss how we can create a SharePoint site using REST API in SharePoint Online Office 365. This will also work fine with SharePoint 2013 and SharePoint 2016. 

Here we have taken two text boxes where a user can put the site name, the site description and a submit button. On click, the site will get created.


The HTML code looks like below:

<div id="CreateSite">
        <strong>Site Name:</strong>
        <br />
        <input type="text" id="txtSiteTitle" />
    <br />
        <strong>Site Description:</strong>
        <br />
        <textarea cols="20" id="txtSiteDescription"></textarea>
    <br />
    <input type="button" id="btnSubmit" value="Create Site" />
<div id="divResults"></div>
Here divResults will display the successful message after the site is created successfully.

Then the script code will be like below. Here in the createSite() method we are retrieving the site title and description from the textboxes and we are making the site URL by removing the space from the title. Other properties which were required to create the site we have hardcoded inside the __metadata.


The whole code we have added inside a script editor web part inside a web part page. 

    $(function () {
    function bindButtonClick() {
        $("#btnSubmit").on("click", function () {
    function createSite() {
        var newSiteTitle = $("#txtSiteTitle").val();
        var newSiteDesc = $("#txtSiteDescription").val();
        var newSiteUrl = newSiteTitle.replace(/\s/g, "");
        var siteUrl = _spPageContextInfo.webAbsoluteUrl;
        var fullUrl = siteUrl + "/_api/web/webinfos/add";
            url: fullUrl,
            type: "POST",
            data: JSON.stringify({
                'parameters': {
                    '__metadata': { 'type': 'SP.WebInfoCreationInformation' },
                    'Url': newSiteUrl,
                    'Title': newSiteTitle,
                    'Description': newSiteDesc,
                    'Language': 1033,
                    'WebTemplate': 'sts#0',
                    'UseUniquePermissions': false
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            success: onQuerySucceeded,
            error: onQueryFailed
    function onQuerySucceeded() {
        $("#divResults").html("Site Created Successfully!");
    function onQueryFailed(sender, args) {

Once you save the page it looks like below. Here put a title for the site and a description for the site. Then click on the Submit button. It will show a successful message once the site is created successfully.

You can navigate to the Site Contents page and you can see the site is created successfully.


If you want to know about Microsoft Flow then you can read below two articles:


Here we have discussed how we can create a site using REST API in SharePoint Online.