How to validate a value from the response in a synthetic test for api test?

Hi,

i have a basic synthetic test for a call api which returns a response.

The response is like:

{

“abc”: {

“efg”: [

{

“ijk”: “hello”,

“klm”: “bye”,

…

How to validate “ijk” is equal to “hello”

i tried this:

var responseBody = response.getResponseBody();

var jsonData = JSON.parse(responseBody);

if (jsonData.abc.efg[0] === “hello”) {

return true;

}else{

return false;

}

The test return script_execution_failed

Thank you

Hi @pseg1984

you can create response validation rule to either pass or fail based on the required fetched response

Regards,

Hi @pseg1984

If you are using rest Api, Go to environment API v2 > Synthetic monitors > PUT.

Peter_Youssef_0-1727522425435.png

  1. create the token with the required scope “ExternalSyntheticIntegration” and use it to unlock the key and execute the command then you can specify response validation rule in the Json file.
  2. you should receive the below message
  • If you’re using rest API, you can utilize the Curl command and execute it without having access to Dynatrace.

BR,

With Set rule for response validation can i add more than 100 values to validate? do we have to separate by comma?

I don’t understand.

Hi @pseg1984 
Very simple SRE and DevOps team are interested in running scripts and Rest APIs instead of exposing User Interfaces for multiple solutions, That’s why I’ve described the second approach as alternative solution, both working as well.

Regards.

Peter.

Ok so let me check for curl command, it looks interesting for me.

Can someone reply to this question?

Hi,

Is it http monitor?

If Yes, please try the bellow option:

Yes it’s HTTP Monitor,

the Set rule for response validation works but i have more than 100 values to valide.

If you content can be retrieved by a RegEx so YES.

Just enable the option and put the right RegEx.