1

I am facing an issue while checking in the file using REST API. The code below works Chrome Firefox and IE except the version 11.0.9600.17914. I tested it on my local IE version 11.0.9600.17905 and the code worked fine. Any ideas about why this might be happening will be greatly appreciated. Have been trying to find out the cause since a long time. Below is the code and the response from the server.

Code

var MyTestCode = (function(){
 var p_RequestDigest = function () {
        return $.Deferred(function (dfd) {
            $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/contextinfo",
                type: "Post",
                headers: {
                    "Accept": "application/json; odata=verbose"
                },
                success: function (data) {
                    //data = JSON.parse(data)
                    dfd.resolve(data.d.GetContextWebInformation.FormDigestValue);
                },
                error: function (data) {
                    dfd.reject(data);
                }
            });
        })
};

 var _CheckInFile = function (config) {
        return $.Deferred(function (dfd) {
            $.when(p_RequestDigest()).then(function (requestDigest) {
                var executor = new SP.RequestExecutor(config.context);
                var info = {
                    url: "_api/web/GetFileByServerRelativeUrl('" + config.FileUrl + "')/CheckIn(comment='" + config.Comments + "', checkintype=0)",
                    method: "POST",
                    headers: {
                        "Accept": "application/json; odata=verbose",
                        "X-RequestDigest": requestDigest
                    },
                    contentType: "application/json;odata=verbose",
                    success: function (data) {
                        //binary data available in data.body
                         console.log("Success")
      dfd.resolve(data);
                    },
                    error: function (err) {
      console.log("Error ", err);
                        dfd.reject(err);
                    }
                };
                executor.executeAsync(info);
            })
        });

    };

 return{
  CheckInFile:_CheckInFile
 }

})()




function executeFucn(){
 var config = {
  context: _spPageContextInfo.siteServerRelativeUrl,
  FileUrl: _spPageContextInfo.siteServerRelativeUrl + "/Documents/File-Name.aspx",
  Comments: "Test"
 }
 MyTestCode.CheckInFile(config)
}

var scriptbase = _spPageContextInfo.siteAbsoluteUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.RequestExecutor.js", executeFucn);

Server Response

{
  statusCode : 400,
  statusText :"Bad Request",
  body : "{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"nl-NL","value":"Onjuist opgemaakte JSON-stream."}}}"
}

Additional Information

  • Onjuist opgemaakte JSON-stream means "Malformed JSON stream."
  • The KB that shows up when you go to IE>Help>About Internet Explorer is KB3065822

1 Answer 1

0

Add "X-HTTP-Method": "MERGE" to your request header. That works fine.

headers: {
    "Accept": "application/json; odata=verbose",
    "X-RequestDigest": requestDigest,
    "X-HTTP-Method": "MERGE"
},

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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