There are a lot of resources around that show how to do this, but I couldn’t find a comprehensive go-to link, so here we are.
You can create a SharePoint site using the REST API. Here’s a fully baked example:
<!-- SiteRequestForm.html: Collect information and create a site for the user. --> <ಕೇಂದ್ರ> <ಮೇಜು> <TR> <ಟಿಡಿ>Site Name:</ಟಿಡಿ> <ಟಿಡಿ><ಇನ್ಪುಟ್ ಕೌಟುಂಬಿಕತೆ="text" ಹೆಸರು="SiteName" ಐಡಿ="SiteName" /></ಟಿಡಿ> </TR> <TR> <ಟಿಡಿ colspan="2"> <ಇನ್ಪುಟ್ ಕೌಟುಂಬಿಕತೆ="submit" ಐಡಿ="CreateSiteButton" ಮೌಲ್ಯ="Create the Site" /> </ಟಿಡಿ> </TR> </ಮೇಜು> </ಕೇಂದ್ರ> <ಸ್ಕ್ರಿಪ್ಟ್ SRC="../Plugins/jquery-1.11.0.min.js"></ಸ್ಕ್ರಿಪ್ಟ್> <ಸ್ಕ್ರಿಪ್ಟ್> ಎಂದು CreateSiteLogicContainer = { createSiteData: { "parameters": { __metadata: { "type": "SP.WebInfoCreationInformation" }, Url: "Paultest1", ಶೀರ್ಷಿಕೆ: "Paultest1", ವಿವರಣೆ: "rest-created web by Paul!", ಭಾಷೆ: 1033, WebTemplate: "sts", UseUniquePermissions: ತಪ್ಪಾದ } }, createSite: ಕ್ರಿಯೆ () { jQuery.support.cors = ನಿಜವಾದ; CreateSiteLogicContainer.createSiteData.parameters.Url = $("#SiteName").ವಾಲ್(); $.ajax({ URL: "https://bigapplesharepoint.sharepoint.com/NBAIADev/_api/web/webinfos/add", ವಿಧಾನ: "POST", headers: { "Accept": "application/json; odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").ವಾಲ್() }, ದಶಮಾಂಶ: JSON.stringify(CreateSiteLogicContainer.createSiteData), success: ಕ್ರಿಯೆ () { ಎಚ್ಚರಿಕೆ("success"); }, ದೋಷ: ಕ್ರಿಯೆ () { ಎಚ್ಚರಿಕೆ("error"); } }); }, wireUpForm: ಕ್ರಿಯೆ () { $("#CreateSiteButton").ಕ್ಲಿಕ್ ಮಾಡಿ(ಕ್ರಿಯೆ () { ಎಚ್ಚರಿಕೆ("About to try and create the site."); CreateSiteLogicContainer.createSite(); }); } } CreateSiteLogicContainer.wireUpForm(); </ಸ್ಕ್ರಿಪ್ಟ್>
When successful, you get a JSON packet in response like this:
My key thoughts and learnings from this include:
- This approach uses jQuery. ಪ್ರಕರಣದಲ್ಲಿ, my jQuery library is located in “../plugins.” You’ll want to change that to point to your favorite JQ location.
- You can copy and paste that whole snippet into a Content Editor Web Part on a page and it should work just fine. You’ll want to change the end point of the API call and make sure you reference JQ correctly.
- The URL is relative to your API’s endpoint. ಪ್ರಕರಣದಲ್ಲಿ, it’s creating sub-sites underneath https://bigapplesharepoint.com
- You don’t need to provide a content-length. Some blog posts and MSDN document implies that you do, but happened for me automatically, which I assume is being handled by the $.ajax call itself.
- This line is required in order to avoid a “forbidden” response: "X-RequestDigest": $("#__REQUESTDIGEST").ವಾಲ್(). There are other ways to do it, but this is pretty nice. I have lost the link to blog that provided this shortcut. H/T to you, mysterious blogger!
Good luck and hope this helps someone out.
</ಕೊನೆಯಲ್ಲಿ>
ನಲ್ಲಿ ಟ್ವಿಟ್ಟರ್ ನನ್ನನ್ನು ಅನುಸರಿಸಿ http://www.twitter.com/pagalvin