Skip to content

Instantly share code, notes, and snippets.

@goodfeel
Created July 29, 2015 02:15
Show Gist options
  • Save goodfeel/0560d511f72a5bdc8f72 to your computer and use it in GitHub Desktop.
Save goodfeel/0560d511f72a5bdc8f72 to your computer and use it in GitHub Desktop.
NewRelic Synthetics API Test Script
/**
* Welcome to the Synthetics JavaScript IDE - API Edition
* You can think of it like node.js lite. Everything you'd expect to find in a
* node.js environment is also available here, with a few notable exceptions:
*
* Feel free to explore, or check out the full documentation
* https://docs.newrelic.com/docs/synthetics/new-relic-synthetics/scripting-monitors/writing-api-tests
* for details.
*/
var assert = require('assert');
//Define your authentication credentials
var hostURL = 'https://URL';
var apiToken = 'Bearer XXXX';
var options = {
//Define endpoint URI
uri: hostURL,
//Define query key and expected data type.
headers: {
'Authorization': apiToken,
'Content-Type': 'application/json'
}
};
//Define expected results using callback function.
function callback (err, response, body){
//Log JSON results from endpoint to Synthetics console.
bodyParsed = JSON.parse(body);
assert.ok(response.statusCode == 200, 'Expected 200 OK response');
assert.ok(bodyParsed.result == 'success', 'Expected success response');
}
//Make GET request, passing in options and callback.
$http.get(options,callback);
@vitalyrychkov
Copy link

thanks, this is helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment