Friday, December 25, 2015

Get minor version of a document using REST API

 function getMinorVersion() {
        var getfilename = document.getElementById("getfilename").value;
        var executor;

        // Initialize the RequestExecutor with the app web URL.
        executor = new SP.RequestExecutor(appweburl);
        executor.executeAsync({
            url: appweburl + "/_api/SP.AppContextSite(@target)/web/getfolderbyserverrelativeurl('/Shared%20Documents/FolderA')/files('" + getfilename + "')/MinorVersion?@target='" + hostweburl + "'",
            method: "GET",
            headers: {
                "Accept": "application/json; odata=verbose"
            },
            success: getMinorVersionSuccessHandler,
            error: getMinorVersionErrorHandler
        });
    }

    // Success Handler
    function getMinorVersionSuccessHandler(data) {
        var jsonObject = JSON.parse(data.body);
        // Display the minor version of the file
        alert("Minor version: " + jsonObject.d.MinorVersion);
    }

    // Error Handler
    function getMinorVersionErrorHandler(data, errorCode, errorMessage) {
        alert("Could not get the file minor version: " + errorMessage);
    }

No comments:

Post a Comment