2

Is it possible to create a site collection using the SharePoint Online REST api?

I found some old notes about using admin.asmx in 2007/2010/2013 but I can't find anything related to SharePoint online or if it still exists.

An example URL would be amazing if it's possible.

  • I've used the PnP library and Flows with Azure functions, but haven't explored the ReST route yet. I'm assuming it would be a lot easier than those 2 methods. – Colbs Dec 13 '18 at 22:26
  • What type of site collection would you like to create ? Do you want to create modern communication and team sites ? – Gautam Sheth Dec 14 '18 at 12:05
0

SharePoint Online Rest API provide endpoint to create a sub site but not site collection, see my reply in the similiar thread:

Create the site collection using ECMAScript, JSOM Or Rest API

And web service http://CentralAdmin/_vti_adm/Admin.asmx is not suitable for SharePoint Online, as there is no CA for SPO, this is for On-Premise Environment.

You could use PnP PowerShell New-PnPSite Command to create a site collection instead:

New-PnPSite

-1

Its possible to create Site collection using the Rest API.

Here is the code for Site Collection if you want to create a Communication Site collection in Tenant.

var body={
    "request":{
        "__metadata":{"type":"SP.Publishing.CommunicationSiteCreationRequest"},
        "AllowFileSharingForGuestUsers":false,
        "Classification":"IT",
        "Description":"Here is my communication site",
        // "SiteDesignId" - use either of the below 3 options
        //"SiteDesignId":"f6cc5403-0d63-442e-96c0-285923709ffc",
        //"SiteDesignId":null,
        "SiteDesignId":"6142d2a0-63a5-4ba0-aede-d9fefca2c767",
        "Title":"My Test Communication Site",
        "Url":"https://tenantname.sharepoint.com/sites/testcommunicationsite",            
        "lcid":1033
    }
};


jQuery.ajax({
    type: "POST",
    url: "https://tenantname.sharepoint.com/_api/sitepages/communicationsite/create",
    contentType: "application/json",
    processData: false,
    data: JSON.stringify(body),
    headers:{
        "accept":"application/json;odata=verbose",
        "content-type":"application/json;odata=verbose",
        "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value
    },        
    success: function () {
        console.log("creation request submitted");
    },
    error: function(data){
        console.log("failure");
        console.log(data);
    }
});

Hope this code helps.

ref: https://gautamdsheth.wordpress.com/2017/10/04/spo-create-communication-sites-using-rest-api/

Here is the code i have got from MS for Subsite.

function createSite() {

        var newSiteTitle = "Site Title Test";

        var newSiteDesc = "Site Title Desc";

        var newSiteUrl = newSiteTitle.replace(/\s/g, "");

        var siteUrl = _spPageContextInfo.webAbsoluteUrl;

        var fullUrl = siteUrl + "/_api/web/webinfos/add";

        $.ajax({

            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() {

       alert("Site Created Successfully!");

    }

    function onQueryFailed(sender, args) {

        alert('Error!');

    }

ref link :https://social.technet.microsoft.com/wiki/contents/articles/37458.sharepoint-online-office-365-create-site-using-rest-api.aspx

  • 1
    This will create a subsite - not a site collection – R. Sperre Dec 14 '18 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.