JSON response checks

Dear all,

1 - I want to check the response for
{“responses”:[{“resultcode”:“200”,“result”:"‘Process successfully done’",“requestId”:“12313”}]}

How can I check resultcode ? I am sut able to get “responses”

2 - Sleep
I want to plut a sleep between 2 api calls. How can I do it ?

Thanks and regards,

Hi @l.gachon - A good start would be to look at my sample API synthetic script.

You will also find information in the documents for Synthetic API testing.

HI Stefan,

Thanks for your answer but I am not sure that it answers to my questions

var info = JSON.parse(body);
assert.ok(shouldDisplayError(info.ErrorMessage), "Error Message: " + info.ErrorMessage);

it will be good for :
{“resultcode”:“200”,“result”:"‘Process successfully done’",“requestId”:“12313”}

è info.resultcode works
But not for
{“responses”:[{“resultcode”:“200”,“result”:"‘Process successfully done’",“requestId”:“12313”}]}

è info.resultcode doesn’t work

what about pause / sleep ?
Thanks
Laurent

@l.gachon, for sleeping there is $browser.sleep():

https://docs.newrelic.com/docs/synthetics/new-relic-synthetics/scripting-monitors/synthetics-scripted-browser-reference#browser-sleep

In your example above for the JSON array, please try:

info.responses[0].resultcode

as in

> console.log(info.responses[0].resultcode);
200

@l.gachon - I wanted to post here to mention that it looks like @llawson missed the fact that you are using a script API test and so $browser.sleep() will actually be unavailable. The Script API simply runs a standard Node.JS script so any of the various methods that can be used within node/javascript can be used for sleeping. Here is a quick link to a Stack overflow article that discusses various methods. http://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep

console.log(info.responses[0].resultcode); works well thx

1 Like

Thanks I found a solution in the previous link !

Cheers,
Laurent

1 Like