cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

JSON.stringify() on requestBody in pre-execution script of HTTP monitor ?

iromaniuk
Newcomer

I am using request.setBody(requestBody) , but getting Bad request response code 400. I can see [object Object] in the synthetic.0.0.log when logging RequestBody

2020-11-03 16:48:11 UTC WARNING [<collector>] [<collector.core>, LogEntryService] Http-Executor-0 [CommonApiController] [HTTP_CHECK-A12AC65899713EC, HTTP_CHECK_STEP-CC3B186211915B8C] RequestBody: [object Object]

See the code below. Should I JSON.stringify() on requestBody , what's wrong here ?

var currSessions=api.randomNextInt();
api.warn("CurrSessions: " + currSessions);
var timestampNow = api.date();
api.warn("Timestamp: " + timestampNow);
var requestBody={
    "type": "LB",
    "series": [
        {
            "timeseriesId": "custom:alteon.CurrSessions",
            "dimensions": {
                "CUSTOM_DEVICE": "Load Balancers"
            },
            "dataPoints": [
                [
                    timestampNow,
                    currSessions
                ]
            ]
        }
    ]
};
api.warn("RequestBody: " + requestBody);
request.setBody(requestBody);
0 REPLIES 0