Help with API Test


I looking for a script that resolves my API endpoint and sees if it gets 200 response code if there is a diff code then mark it as an alert.

In able to curl the API endpoint and get 200 response code am trying put a same kind of solution and throw an alert if the code is different

Hi, @karthick.gopalakrish: When you create a Synthetics API test, the script editor is populated with a sample script that does almost exactly what you want: Send a request to an URL and confirm that it returns a 200 response:

var assert = require('assert');

  // Callback
  function (err, response, body) {
    assert.equal(response.statusCode, 200, 'Expected a 200 OK response');

After you create the Synthetics monitor, you may create an alert condition that will violate if the script fails.

1 Like