Currently New Relic supports two versions of the synthetic monitoring API: v1 and v3. Version 3 was released October 2016. Version 1 is deprecated and will eventually no longer be available. No termination date has been announced. However, no further development or modifications will be made to v1.
Advertencia
Recommendation: Create new monitors using the v3 synthetics API and migrate v1 scripts to their v3 equivalent.
You must use your Admin User's API key to make synthetics REST API calls. The account's REST API key will not work.
Advertencia
The synthetics REST API limits an account's rate of requests to three requests per second. Requests made in excess of this threshold will return a 429 response code.
These examples show curl commands:
To view a list of all monitors in New Relic for your account, send a GET request to https://synthetics.newrelic.com/synthetics/api/v1/monitors. For example:
A successful request will return a 200 OK response. The data returned will be a JSON object in the following format:
{
"count": integer,
"monitors": [
{
"id": UUID,
"name": string,
"type": string,
"frequency": integer,
"uri": string,
"locations": array of strings,
"status": string,
"slaThreshold": double,
"userId": integer,
"apiVersion": string
}
]
}
To view a single existing monitor in New Relic, send a GET request to https://synthetics.newrelic.com/synthetics/api/v1/monitors/{id}. Replace the {id} in the following example with the specific monitor ID.
A successful request will return a 200 OK response. The data returned will be a JSON object in the following format:
{
"id": UUID,
"name": string,
"type": string,
"frequency": integer,
"uri": string,
"locations": array of strings,
"status": string,
"slaThreshold": double,
"userId": integer,
"apiVersion": string
}
An invalid monitor ID will return the error 404 Not Found: The specified monitor doesn't exist.
To add a new monitor to your account in New Relic, send a POST request to https://synthetics.newrelic.com/synthetics/api/v1/monitors with a JSON payload that describes the monitor:
"frequency": integer (minutes) [required, must be one of 1, 5, 10, 15, 30, 60, 360, 720, or 1440],
"uri": string [required for SIMPLE and BROWSER type],
"locations": array of strings (send a GET request to https://synthetics.newrelic.com/synthetics/api/v1/locations to get a list of valid locations) [at least one required],
"status": string (ENABLED, DISABLED) [required],
"slaThreshold": double,
}
In addition, to add a scripted monitor via the REST API, call an additional API endpoint to send the script for the monitor just created.
A successful request will return a 201 Created response, with the URI of the newly-created monitor specified in the location header. Possible error codes include:
400 Bad Request: One or more of the monitor values is invalid, or the format of the request is invalid. For example, the frequency is out of bounds or one or more of the specified locations is invalid (See the error message in the body of the response.)
402 Payment Required: Creating the monitor will increase your scheduled checks past your account's purchased check limit.
To update an existing monitor in New Relic, send a PUT request to https://synthetics.newrelic.com/synthetics/api/v1/monitors/{id}. In addition, for scripted monitors, follow the procedures to update the BASE64 encoded script.
Replace the {id} in the following example with the specific monitor ID, and replace the Synthetics REST API attributes with your specific values.
PUT requests are intended to replace target entities, so all attributes required in the JSON payload when creating a new monitor are also required when updating an existing monitor.
A successful request will return a 204 No Content response, with an empty body. Possible error codes include:
400 Bad Request: One or more of the monitor values is invalid, or the format of the request is invalid. For example, the frequency is out of bounds or one or more of the specified locations is invalid (See the error message in the body of the response.)
404 Not Found: The specified monitor does not exist.
To delete an existing monitor in New Relic, send a DELETE request to https://synthetics.newrelic.com/synthetics/api/v1/monitors/{id}. Replace the {id} in the following example with the specific monitor ID.
A successful request will return a 204 No Content response, with an empty body. An unsuccessful request will return the response, 404 Not Found: The specified monitor does not exist.
To retrieve the list of valid locations in New Relic, use the following command.
curl -v \
-X GET -H 'X-Api-Key:{Admin_User_Key}' https://synthetics.newrelic.com/synthetics/api/v1/locations
Managing scripted monitors
In addition to the general API, there are several API methods for the scripted browser (SCRIPT_BROWSER) and api test (SCRIPT_API) monitor types.
These examples show curl commands.
To view the script associated with a specific SCRIPT_BROWSER or SCRIPT_API monitor in New Relic for your account, send a GET request to https://synthetics.newrelic.com/synthetics/api/v1/monitors/{id}/script. Replace the {id} with the specific monitor ID. For example:
To update the script associated with a specific SCRIPT_BROWSER or SCRIPT_API monitor in New Relic for your account, send a PUT request to https://synthetics.newrelic.com/synthetics/api/v1/monitors/{id}/script with a JSON payload that contains the scriptText (required). The scriptLocations data is required only for private locations with Verified Script Execution turned on.
The password used to generate the HMAC string must match the password set for the private location. When generating the HMAC string, use the SHA256 algorithm.
{
"scriptText": BASE64 encoded String,
"scriptLocations": [
{
"name": Location name,
"hmac" BASE64 encoded String of SHA256 HMAC for location
}
]
}
Replace the {id} with the specific monitor ID. Here is an example for the script:
var assert = require('assert');
assert.equal('1', '1');
This example uses password as the password for the scriptLocation.
A successful request will return a 204 No Content response with an empty body. Possible error codes include:
400 Bad Request: Invalid BASE64 encoded string for scriptText or hmac.
403 Forbidden: The specified monitor is not of the type SCRIPT_BROWSER or SCRIPT_API.
404 Not Found: The specified monitor does not exist.
Scripted browser example
Here is an example of using New Relic's REST API and the bash script to create a scripted browser monitor.
The following example shows curl commands to create a scripted browser monitor.
At the top of the script, replace the variables with your specific values.
For the scriptfile variable, identify the filename for the script to be created. Here is a sample script that can be saved as sample_synth_script.js to use in the example:
String: The URI for SIMPLE and BROWSERmonitor types; for example, http://my-site.com. Optional for SCRIPT_BROWSER and SCRIPT_API.
userID
Integer: The specific user ID.
Specific monitor endpoint
When making REST API calls for a specific monitor, include the monitor_uuid as part of the endpoint. The monitor_uuid is the GUID which is part of the URL. For example, a selected synthetics monitor has this URL: