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

**URL:** <https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028>\
**Category:** Open Q&A\
**Tags:** synthetic-monitoring\
**Created:** [September 28, 2024, 1:08am UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028 "2024-09-28T01:08:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pseg1984](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pseg1984](https://community.dynatrace.com/u/pseg1984)\
**Post date:** [September 28, 2024, 1:08am UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/1 "2024-09-28T01:08:16Z")

</div>

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] ===&nbsp;“hello”) {

return true;

}else{

return false;

}

The test return script\_execution\_failed

Thank you

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [September 28, 2024, 11:16am UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/2 "2024-09-28T11:16:33Z")

</div>

Hi&nbsp;[@pseg1984](https://community.dynatrace.com/user/80625)

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

 ![response validation.png](https://global.discourse-cdn.com/dynatrace/original/3X/d/3/d3949905feb599138d0faff67a02145ce7925745.png)

Regards,

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [September 28, 2024, 11:28am UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/3 "2024-09-28T11:28:18Z")

</div>

Hi&nbsp;[@pseg1984](https://community.dynatrace.com/user/80625)

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

![Peter_Youssef_0-1727522425435.png](https://global.discourse-cdn.com/dynatrace/optimized/2X/a/af88102b9daf26f01ecb475ab05bf2abaf5eced3_2_690x38.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,

---

<div class="post-metadata">

**Author:** ![pseg1984](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pseg1984](https://community.dynatrace.com/u/pseg1984)\
**Post date:** [September 28, 2024, 11:57am UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/4 "2024-09-28T11:57:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pseg1984](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pseg1984](https://community.dynatrace.com/u/pseg1984)\
**Post date:** [September 28, 2024, 11:58am UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/5 "2024-09-28T11:58:09Z")

</div>

I don’t understand.

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [September 28, 2024, 2:47pm UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/6 "2024-09-28T14:47:04Z")

</div>

Hi&nbsp;[@pseg1984](https://community.dynatrace.com/user/80625)&nbsp;  
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.

---

<div class="post-metadata">

**Author:** ![pseg1984](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pseg1984](https://community.dynatrace.com/u/pseg1984)\
**Post date:** [September 28, 2024, 4:18pm UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/7 "2024-09-28T16:18:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pseg1984](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pseg1984](https://community.dynatrace.com/u/pseg1984)\
**Post date:** [September 28, 2024, 6:30pm UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/8 "2024-09-28T18:30:18Z")

</div>

Can someone reply to this question?

---

<div class="post-metadata">

**Author:** ![Malaik](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/malaik/32/32673_2.png) [@Malaik](https://community.dynatrace.com/u/Malaik)\
**Post date:** [September 29, 2024, 8:17am UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/9 "2024-09-29T08:17:54Z")

</div>

Hi,

Is it http monitor?

If Yes, please try the bellow option:

 ![Malaik_0-1727597865610.png](https://global.discourse-cdn.com/dynatrace/original/2X/a/a6092ca9f3be32f4a7cbf33d30d2f74e21f9ee02.png)

---

<div class="post-metadata">

**Author:** ![pseg1984](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pseg1984](https://community.dynatrace.com/u/pseg1984)\
**Post date:** [September 29, 2024, 5:59pm UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/10 "2024-09-29T17:59:38Z")

</div>

Yes it’s HTTP Monitor,

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

---

<div class="post-metadata">

**Author:** ![Malaik](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/malaik/32/32673_2.png) [@Malaik](https://community.dynatrace.com/u/Malaik)\
**Post date:** [September 30, 2024, 6:29am UTC](https://community.dynatrace.com/t/how-to-validate-a-value-from-the-response-in-a-synthetic-test-for-api-test/48028/11 "2024-09-30T06:29:32Z")

</div>

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

Just enable the option and put the right RegEx.
