Is it possible to create a document-library via SharePoint Rest API?
I assume you mean SharePoint 2013. In this case, of course, you can create lists, including document libraries via REST, as described here. For the document library you should use 101 as the BaseTemplate.
url: http://site url/_api/web/lists
method: POST
body: { '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true, 'BaseTemplate': 101,
'ContentTypesEnabled': true, 'Description': 'My doc. lib. description', 'Title': 'Test' }
Headers:
Authorization: "Bearer " + accessToken
X-RequestDigest: form digest value
accept: "application/json;odata=verbose"
content-type: "application/json;odata=verbose"
content-length:length of post body
If you need to access this endpoint from a Java-based application, you can use a library, like Apache HttpComponents that supports this kind of HTTP-based communication. You find several samples here.
As far as I the official documentation of this API, and other samples on the web (like this and this one) understand, the body of the request can be set in this case as a StringEntity
instance via the setEntity
method of the HttpPost
object:
String jsonString = "{ '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true, 'BaseTemplate': 101,
'ContentTypesEnabled': true, 'Description': 'My Documents Library', 'Title': 'Documents' }";
HttpEntity e = new StringEntity(jsonString);
httpPost.setEntity(e);
-
-
Do you mean JavaScript (like from the context of a SharePoint app) or really Java (for example from a context of a console application on Unix or some kind server side code)? – pholpar Apr 8 '15 at 7:53
-
-
-
1@VadimGremyachev, thanks, it was a copy-paste error. Next time feel free to complete my code if you find such mistakes. – pholpar Apr 8 '15 at 8:23
How to create a Document library using SharePoint REST:
url: http://site url/_api/web/lists
method: POST
body: { '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true, 'BaseTemplate': 101,
'ContentTypesEnabled': true, 'Description': 'My Documents Library', 'Title': 'Documents' }
Headers:
Authorization: "Bearer " + accessToken
X-RequestDigest: form digest value
accept: "application/json;odata=verbose"
content-type: "application/json;odata=verbose"
content-length:length of post body
References