Created
July 29, 2015 02:15
-
-
Save goodfeel/0560d511f72a5bdc8f72 to your computer and use it in GitHub Desktop.
NewRelic Synthetics API Test Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks, this is helpful