Your data. Anywhere you go.

New Relic for iOS or Android

Download on the App Store    Android App on Google play

New Relic Insights App for iOS

Download on the App Store

Learn more

Close icon

Insights post custom events with randomized attribute values



Sample script showing how to use the API Test type of script to insert random data into Insights.

var myAccountID = {MyAccountID}
var myLicenseKey = {MyInsertKey}
var assert = require('assert');

function randomInt (low, high) {
    return Math.floor(Math.random() * (high - low) + low);
var options = {
        url: ""+myAccountID+"/events",
        body: '[{"eventType":"SyntheticsEvent","account":'+randomInt(1,100)+',"amount":'+randomInt(1,10000)+'}]',
        headers: {
                'X-Insert-Key': MyInsertKey,
                'Content-Type': 'application/json'

function callback(error, response, body) {
  console.log(response.statusCode + " status code")
  assert.ok(response.statusCode == 200, 'Expected 200 OK response');  
        var info = JSON.parse(body);
  assert.ok(info.success == true, 'Expected True results in Response Body, result was ' + info.success);
  console.log("End reached");
$, callback);

Sequence steps with Q
Feature regression - no more start time in waterfall

I don’t really understand what the point of this is… Would you combine this with a scripted browser test to log custom data about that test to Insights? Or…? Can you provide some examples of where this would be useful? Thank you


This script is meant to simply show how to use the API test in order to test an authenticated API endpoint. It could be combined with an Insights specific query/post with a browser test or used for testing any customer facing API. We are using a similar Synthetics check internally to help ensure our Insights API is available to customers.