CleanSpeak SaaS Example (jQuery)
Example API call using jQuery.
HTML
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<div id="results">
<h1>aiueo</h1>
</div>
CSS
#results {
display: block;
unicode-bidi: embed;
font-family: monospace;
white-space: pre;
}
JavaScript
// This is a template you may use to test the API call.
// Replace '<INSERT SaaS API Key Here>' with your API key.
// http://api.jquery.com/jquery.ajax/
var results = $('#results');
$.ajax({
url: 'http://api.inversoft.com:8211/content/item/filter',
type: 'POST',
contentType: 'application/json',
headers: {
'Authorization': '<INSERT SaaS API Key Here>'
},
data: JSON.stringify({
'content': 'I hate you. You are a jerk!'
}),
success: function(data, statusText, xhr) {
results.html(JSON.stringify(data, null, 2));
},
error: function(xhr) {
results.html('Status: ' + xhr.status + '\n');
if (xhr.status === 401) {
results.html('Not Authenticated, change the API key.');
} else if (xhr.status === 400) {
var response = JSON.parse(xhr.responseText);
results.html('Failure: \n' + JSON.stringify(response, null, 2));
} else {
results.html(xhr.errorText);
}
}
});