Introduction
We can use the SharePoint 2013 Representational State Transfer (REST) service to do the same tasks you can do when you use the .Net CSOM and JSOM.
Here I will explain about CreateList in SharePoint 2013 using the REST API.
Procedure
- On your Developer Site, open the "Napa" Office 365 Development Tools and then choose Add New Project.
- Choose the App for SharePoint template, name the project Create Site and then choose the Create button.
Prerequisites
These are important steps to be done before creating the app.
Specify the permissions that your app needs as in the following:
- Choose the Properties button at the bottom of the page.
- In the Properties window, choose Permissions.
- In the Content category, set Write permissions for the Tenant scope.
- In the Social category, set Read permissions for the User Profiles scope.
- Close the Properties window.
Expand the Scripts node, choose the App.js file and delete the contents of the file and replace with the following code:
- 'use strict';
- var hostweburl;
- var appweburl;
-
- $(document).ready(function () {
- hostweburl= decodeURIComponent(getQueryStringParameter("SPHostUrl"));
- appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
- });
- function createSPList() {
- $.ajax(
- {
- url: appweburl +
- "/_api/SP.AppContextSite(@target)/web/lists?@target='" +
- hostweburl + "/sites/apps'",
- type: "POST",
- data: JSON.stringify({
- '__metadata': { 'type': 'SP.List' },
- 'AllowContentTypes': true,
- 'BaseTemplate': 100,
- 'ContentTypesEnabled': true,
- 'Description': 'My TestCustomList description',
- 'Title': 'TestCustomList'
- }),
- headers: {
- "accept": "application/json;odata=verbose",
- "content-type": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val()
- },
- success: successHandler,
- error: errorHandler
- });
- }
- function successHandler() {
- $('#message').text('Success');
- }
- function errorHandler(data, errorCode, errorMessage) {
- $('#message').text('Error ' + errorMessage);
- }
- function getQueryStringParameter(paramToRetrieve) {
- var params =
- document.URL.split("?")[1].split("&");
- var strParams = "";
- for (var i = 0; i < params.length; i = i + 1) {
- var singleParam = params[i].split("=");
- if (singleParam[0] == paramToRetrieve)
- return singleParam[1];
- }
- }
Once you completed the code part then run the project.
Once you deployed the app select the
Click here to launch your app in new window link. It will redirect to another page.
![]()
![]()
I hope you have enjoyed this.