var activeEndpoint = ""; var activeParams = []; function init(){ //activate json highlighting for all sample response sections highlight()} //all of the below functions are used to create the Try It! modal: function tryit(endpoint) { window[endpoint](); } function setModalTitle(endpoint) { document.getElementById("tryitModalLabel").innerHTML = endpoint; } function setParams(params){ let count = params.length; //create table HTML let html = ''; let i; for(i = 0; i< count; i++) { html = html+''; } html = html+"
'+params[i]+'
"; document.getElementById("tryit-params-table").innerHTML= html; document.getElementById("tryit-response-box").innerHTML = ""; } function runExample() { //generate URL let urlSend = getEnv()+"/"+activeEndpoint+"?tmprqst=appsetApiDocs"; //assemble url params from inputs let count = activeParams.length; let i; for(i = 0; i< count; i++) { urlSend = urlSend+"&"+activeParams[i]+"="+encodeURI(document.getElementById("tryit-param-"+activeParams[i]).value); } //make request let Http = new XMLHttpRequest(); Http.open('GET', urlSend); Http.send(); Http.onreadystatechange=function(){ if(this.readyState==4 && this.status==200){ let parsedJSON = JSON.parse(Http.responseText) var str = JSON.stringify(parsedJSON, undefined, 4); output(str); output(syntaxHighlight(str)); } } } function output(inp) { document.getElementById("tryit-response-box").innerHTML = inp; } function syntaxHighlight(json) { json = json.replace(/&/g, '&').replace(//g, '>'); return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { var cls = 'number'; if (/^"/.test(match)) { if (/:$/.test(match)) { cls = 'key'; } else { cls = 'string'; } } else if (/true|false/.test(match)) { cls = 'boolean'; } else if (/null/.test(match)) { cls = 'null'; } return '' + match + ''; }); } function formatSampleResponseJSON(id) { let json = document.getElementById(id).innerHTML; let parsedJSON = JSON.parse(json) let str = JSON.stringify(parsedJSON, undefined, 4); let highlighted = syntaxHighlight(str); document.getElementById(id).innerHTML = highlighted; }