简体   繁体   中英

Is it possible to create document libraries in SharePoint Online in code using Rest API?

Is it possible to create document libraries in code using the Rest API? and if so how?

I've created folders and files etc through the rest API but cannot find anything on creating document libraries

I am assuming that it wouldn't be too dissimilar to creating a folder if its possible

Sample code for your reference.

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript">
        function createNewLibraryByRest() {
            var newListName = "RestApiLib";
            var listEndPoint = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/";
            $.ajax({
                url: listEndPoint,
                method: "POST",
                data: JSON.stringify({
                    '__metadata': { 'type': 'SP.List' },
                    'AllowContentTypes': true,
                    'BaseTemplate': 101, //101 for document library
                    'ContentTypesEnabled': true,
                    'Description': 'Description',
                    'OnQuickLaunch': true,
                    'Title': newListName
                }),
                headers: {
                    "content-type": "application/json;odata=verbose",
                    "X-RequestDigest": $("#__REQUESTDIGEST").val()
                },
                success: function (data) {
                    alert('Library Created!');
                },
                error: function (err) {
                    alert(err.responseText);
                }
            });

        }
    </script>
    <input id="Button1" type="button" onclick="createNewLibraryByRest()" value="createNewLibraryByRest" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM