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

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

pseg1984
Participant

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

10 REPLIES 10

Hi @pseg1984 

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

response validation.png

Regards,

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

Can someone reply to this question?

Malaik
DynaMight Champion
DynaMight Champion

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

Just enable the option and put the right RegEx.

Sharing Knowledge

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,

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.

Malaik
DynaMight Champion
DynaMight Champion

Hi,

 

Is it http monitor?

 

If Yes, please try the bellow option:

Malaik_0-1727597865610.png

 

Sharing Knowledge

Yes it's HTTP Monitor,

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

Featured Posts