Learn how to create lists in SharePoint 2013 using REST interface. This blog will help you learning the basics of REST API and how it works in SharePoint.
Steps
- Edit your SharePoint page and a Content Editor WebPart.
- Copy the below code and save it as txt format in your Site Assets library.
- Get the txt file link and give it in the CEWP.
- Click the createlist button.
That's it.
- <script type="text/javascript" src="https://gowthamr.sharepoint.com/sites/Test1/SiteAssets/jquery.min.js"></script>
-
-
- <script type="text/javascript">
-
- $(document).ready(function(){
- alert('test');
-
- $("#btnClick").click(function(){
-
- var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists";
- alert(requestUri);
- $.ajax({
- url: requestUri,
- type: "POST",
- data:JSON.stringify({'__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true,'BaseTemplate': 100, 'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'Office365' }),
- headers: {
- "accept": "application/json;odata=verbose",
- "content-type": "application/json;odata=verbose",
-
- "X-RequestDigest": $("#__REQUESTDIGEST").val()
- },
-
- success: onSuccess,
-
- error: onError
-
- });
-
- function onSuccess(data) {
-
- alert(data+ ' List Created');
- }
-
- function onError(error) {
-
-
- }
-
- });
-
- });
-
- </script>
-
- <input type="button" id="btnClick" value="Click to Create List"/>
Was my blog is helpful to you? Please post your comment.