301 error in Synthetic monitor

The synthetic monitor was working perfectly and suddenly getting 301 error in the script and attached is the screen shot of that .
What the script does - It runs the url and the url return backs a healthy status if the system is healthy and parses the output of it .

When manually i put the url in the browser and execute i am able to get the healthy status back from the system but getting 301 when ran from the scripted api.

Hi, @Sanjay.Venkateshan: A 301 status is a redirect; you need to figure out the URL to which your site is redirecting, and change your script to use that URL.

You may use the command curl -iL to follow redirects. For example, when I request http://philweber.com, the server returns two redirects: first, it replaces http with https; then it adds www to the domain:

If I had an API script that returned a 301, I would need to change it to request the final location, https://www.philweber.com/.

Thanks philweber - was very useful.

The 301 is solved - but still getting the parse error.From the browser if i hit the url(the new url) i get the response as
{
“domain”: “xxx-2.amazonaws.com”,
“region”: “xxx”,
“serviceName”: “xxx”,
“status”: “healthy”,
“version”: “xxx”,
“environmentName”: “prod”,
“errors”: [],
“xxxStatus”: “healthy”,
“xxxExecutionTime”: “217ms”,
“xxx”: “416ms”,
“xxx”: “healthy”,
“executionTime”: “929ms”
} and by this response i was using the below script to validate before

var request = require('request');
var assert = require('assert');
var options = {
  'method': 'GET',
  'url': 'https://xxx.com
  'headers': {
    'Accept': 'application/json',
      }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
  assert.ok(response.statusCode == 200, 'Expected 200 OK response');  
  var info = JSON.parse(response.body);
  assert.ok(info.status === 'healthy', 'Expected status to be healthy');  
});

But now via terminal by using the curl -il xxx.com i am not getting the above response and just getting the below response

HTTP/1.1 200 OK
Content-Type: text/html
Cache-Control: no-cache, no-store
Connection: close
Content-Length: 904
X-Iinfo:xxx
Set-Cookie: visid_incap_2682446=D+g49Jo0S/xxx; expires=Thu, 12 Jan 2023 08:08:54 GMT; HttpOnly; path=/; Domain=.xxxcom
Set-Cookie: ixxxpath=/; Domain=.xxx.com

<html style="height:100%"><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><meta name="format-detection" content="telephone=no"><meta name="viewport" content="initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><script src="/kie-Yes-him-To-the-To-mocking-and-do-mise-I-prom" async></script></head><body style="margin:0px;height:100%"><iframe id="main-iframe" src="/_Incapsula_Resource?SWUDNSAI=xxx=GET" frameborder=0 width="100%" height="100%" marginheight="0px" marginwidth="0px">Request unsuccessful. Incapsula incident ID: xxx</iframe></body></html>%            

I see this as the reason for the parse error - any ideas to move forwards from here @philweber

@mcaron when you have time can you help here - Thanks

It looks like your endpoint no longer returns health status? If that is the case, there is not much you can do about it in Synthetics. You will need to find a different URL to get the data you want.

ohh , but hitting the url in the browser returns me the health status @philweber ?

Maybe try using a scripted browser monitor rather than an API test? Perhaps the page relies on JavaScript, which must run in a browser.

@philweber you are correct .The above test is working in a scripted browser monitor but not in an API test .Can you kindly explain the reason behind this?? Thanks in advance.

Because a browser can execute JavaScript, and an API test cannot.

Got it - Thanks @philweber