VersionOne API: Barebones Editor Step 1: Use jQuery to Fetch a Project Asset as JSON
Query the VersionOne Data API using just jQuery and return the result as JSON.
JavaScript
var host = "http://eval.versionone.net"; // Remote web server root
var service = host + "/platformtest/rest-1.v1/Data/" // Path to the REST service
var assetQueryPath = "Scope/0" // Location of an Asset to fetch
var headers = {
Authorization: "Basic " + btoa("admin:admin"), // Necessary to authenticate, since we won't have a login cookie from JSFiddle
Accept: 'haljson' // The format that we want the response in. Without this, we get XML.
};
var settings = { // Parameters jQuery's ajax function needs to make our GET request
url: service + assetQueryPath,
headers: headers,
dataType: 'json' // Hint to jQuery, that the response should be JSON data
};
$.ajax(settings)
.done(function(data) { // Callback for when the server responds properly
beautifulJson = JSON.stringify(data, null, 4); // Pretty print our JSON with indentation
$("body").html('<pre>' + beautifulJson + '</pre>'); // Tack it into the DOM
notAsPrettyJson = JSON.stringify(data);
console.log(notAsPrettyJson.length);
})
.fail(function(jqXHR) { // Callback for when the server "blows up". Change assetQueryPath to "SSSSScope/0" to see!
$('body').html(jqXHR.responseText);
});