0

Actually i tried out all the ways to create but of no use getting 403 forbidden error even though having full access(read/write/update). even look into this but no luck How to create a folder in Sharepoint using Java and RESTFul API?.

please tell how to create folders in sharepoint in java through rest call ??

1

Error 403 occurs because of the failure of security validation in the page. You need to include Form-Digest Value in the REST API.

Refer the code below.

var _formDigest=getFormDigest();

var url = "http://<site>" + "/_api/lists/getByTitle('MyLib')/rootfolder/folders/add('MyFolder')";
$.ajax({
    url: url,
    type: "POST",
    xhrFields: { withCredentials: true },
    headers: { "accept": "application/json;odata=verbose", "x-requestdigest": _formDigest },
    success: function (data) {
        console.log("Done..");
    },
    error: function () {
        console.log("Error Occured");
    }
});

function getFormDigest() {
    $.ajax({
        url: "http://<site>" + "/_api/contextinfo",
        type: "POST",
        dataType: "json",
        headers: { "Accept": "application/json; odata=verbose" },
        xhrFields: { withCredentials: true },
        async: false,
        success: function (data) {
            _formDigest = data.d.GetContextWebInformation.FormDigestValue;
            console.log(data.d.GetContextWebInformation.FormDigestValue);
        },
        error: function (error) {
            console.log(error.responseJSON.error.message.value);
        }
    });
    return _formDigest;
}

The above code should work, but in your case since you are calling the api from JAVA code (I assume) you need to make certain changes in the SharePoint Server.

Please refer this LINK if you get other issues like CORS etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.