current (GET)
{server}/api/v1/printer/current
Description
Returns the name of the printer selected in the underlying print processor.
Applies to:
- ScriptX.Services for Windows PC 2.19 and later.
Response model
string
- String name of the printer
Example usage
Request
<h5>Response <span id="response-status"></span></h5>
<textarea id="response" readonly="readonly" rows="3" class="codefont"></textarea>
<h5>Response headers</h5>
<textarea id="headers" readonly="readonly" rows="3" class="codefont"></textarea>
document.addEventListener("DOMContentLoaded", function() {
document.getElementById('btn_runcode').addEventListener('click', function() { callServer(); });
});
function callServer() {
document.getElementById('response-status').textContent = "(waiting)";
const apiUrl = "/api/v1/printer/current";
const headers = new Headers({
"Authorization": "Basic " + btoa("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + ":"),
"Content-Type": "application/json"
});
fetch(apiUrl, { method: "GET", headers: headers })
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
document.getElementById('response-status').textContent =
'(status: ' + response.status + ' ' + response.statusText + ')';
return response.json().then(data => {
// show JSON response in textarea element
document.getElementById('response').value = JSON.stringify(data, null, " ");
// do something with the printer name
console.log("Printer is " + data);
return response.headers;
});
})
.then(headers => {
// show response headers in textarea element
let headersText = "";
for (let pair of headers.entries()) {
headersText += `${pair[0]}: ${pair[1]}\n`;
}
document.getElementById('headers').value = headersText;
})
.catch(error => {
document.getElementById('response-status').textContent = '(error: ' + error.message + ')';
document.getElementById('response').value = "Failed to fetch data.";
});
}