REST API supports only the format given below, so please be careful before executing your code.
The method given below will retrive all the folders under this Web.
- url: http://site url/_api/web/folders
- method: GET
- headers:
- Authorization: "Bearer " + accessToken
- accept: "application/json;odata=verbose"
Example
Copy the format given below in your Browser and you will get the JSON data, which is given below.
Source code
Copy the code given below and paste in your SharePoint ADD-IN.
Create a folder in SharePoint O365, using REST API.
- var hostweburl;
- var appweburl;
-
-
- $(document).ready(function () {
-
- hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
- appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
-
- $.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js", runCrossDomainRequest);
- });
-
-
- function runCrossDomainRequest() {
- var executor = new SP.RequestExecutor(appweburl);
- executor.executeAsync({
- method: POST
- url:appweburl+"/_api/web/folders"
- body: { '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '/Documents/CustomFolder'}
- 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
- success: successHandler
- error: errorHandler
- });
- }
-
-
- 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];
- }
- }
Was my blog helpful?
Post your feedback here. Thanks for reading my blog.