# How to extract values from response body

**URL:** <https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376>\
**Category:** Synthetic Monitoring\
**Tags:** http-monitor\
**Created:** [August 11, 2021, 7:15pm UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376 "2021-08-11T19:15:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [August 11, 2021, 7:15pm UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/1 "2021-08-11T19:15:38Z")

</div>

Hi guys,

Customer asks to monitor OPEN APIC with synthetic so we create http checks with token saved in the vault.

The issue here is that the tokens got only 10 hours lifetime and we need to generate a new token with rest api every hour.

Our intension now is to call the rest api that generate the token on OPEN APIC and with value from the response body to set a value (with&nbsp;_api.setValue(key, value)_) for the next step which will send dynatrace vault rest api to change the value of the token to the new one.

We need your help here with how to extract values from response body in the post execution step with&nbsp;_response.getResponseBody()_ , how can we extract&nbsp;a value after **token="** till the next **"** from the response body?

Thanks in advance

Yos

---

<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:** [August 12, 2021, 11:46am UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/2 "2021-08-12T11:46:00Z")

</div>

Hello

I think it’s possible using Request Attributes

More details here [Request Attributes](https://www.dynatrace.com/support/help/how-to-use-dynatrace/transactions-and-services/request-attributes/)

---

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [August 12, 2021, 1:19pm UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/3 "2021-08-12T13:19:19Z")

</div>

Hi [@Malaik](https://community.dynatrace.com/user/23195)

Question is about&nbsp; **post-execution script** &nbsp;in **http monitor**.

How can we implement RA in http monitor?

Yos

---

<div class="post-metadata">

**Author:** ![alvaro\_sanchez](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@alvaro\_sanchez](https://community.dynatrace.com/u/alvaro_sanchez)\
**Post date:** [August 12, 2021, 2:43pm UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/4 "2021-08-12T14:43:21Z")

</div>

Hi Yosi,

As the response body is a string, I’d say using a regex match would do the trick, with a capture group somewhat like this (adapt it to the format of your token of course):

api.setValue(“token”, responseBody.match(new RegExp(“token=\”([A-z0-9]+)\“”))[1])

Regards,

Álvaro

---

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [August 12, 2021, 3:37pm UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/5 "2021-08-12T15:37:46Z")

</div>

Hi&nbsp;[@alvaro\_sanchez](https://community.dynatrace.com/user/18994)

Great , will give it a try next week at customer site and will update !

Thanks a lot

Yos

---

<div class="post-metadata">

**Author:** ![MichalGebacki](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/michalgebacki/32/41585_2.png) [@MichalGebacki](https://community.dynatrace.com/u/MichalGebacki)\
**Post date:** [April 22, 2022, 12:43pm UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/6 "2022-04-22T12:43:22Z")

</div>

Hi [@Yosi\_Neuman](https://community.dynatrace.com/user/6931)!

I’m curious how this issue has ended eventually, were you able to find a desired solution as promised last year?&nbsp;:grinning\_face\_with\_smiling\_eyes:

Best regards!

---

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [April 22, 2022, 3:05pm UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/7 "2022-04-22T15:05:15Z")

</div>

Hi&nbsp;[@Michal\_Gebacki](https://community.dynatrace.com/user/44566)

As far as I remember it works OK.

I have accepted&nbsp;[@alvaro\_sanchez](https://community.dynatrace.com/user/18994)&nbsp; answer as a solution&nbsp; and sorry for the “slight” delay in doing that&nbsp;:facepalm:

Yos

---

<div class="post-metadata">

**Author:** ![jkinner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jkinner/32/2536_2.png) [@jkinner](https://community.dynatrace.com/u/jkinner)\
**Post date:** [November 15, 2022, 8:23pm UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/8 "2022-11-15T20:23:48Z")

</div>

I can confirm that you can use regex in the post-execution synthetic script. Here is who I did it for our application.

 ![jkinner_0-1668543806920.png](https://global.discourse-cdn.com/dynatrace/original/2X/2/211691d63083217819dd3506997b06b5183b1cb9.png)

---

<div class="post-metadata">

**Author:** ![jmodeorain14](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jmodeorain14](https://community.dynatrace.com/u/jmodeorain14)\
**Post date:** [September 14, 2023, 8:44am UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/9 "2023-09-14T08:44:03Z")

</div>

Hi,

I’m trying to capture a specific value from the response of a HTTP (API) request.

I have tried the approaches suggested by&nbsp;[@alvaro\_sanchez](https://community.dynatrace.com/user/18994)&nbsp;and&nbsp;[@jkinner](https://community.dynatrace.com/user/55548)&nbsp;above, but with no success.

I’ve attached an example of the response from the API request.

I specifically need to capture the value returned for “policyNo” into a new variable, “policyNumber”.

Does anyone have any suggestions on how I can get this working?

jmodeorain14  
[sample\_response.txt](https://community.dynatrace.com/uploads/short-url/re5yWS1ulu232XgnGpFZ8MxFxKr.txt) (142 Bytes)

---

<div class="post-metadata">

**Author:** ![jmodeorain14](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jmodeorain14](https://community.dynatrace.com/u/jmodeorain14)\
**Post date:** [September 22, 2023, 8:01am UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/10 "2023-09-22T08:01:53Z")

</div>

I was able to extract the value of policyNo from the response body.

In case anyone is interested or has a similar challenge in future, here is the post-execution script I used:

![jmodeorain14_0-1695369653731.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/11557c8eda8a56b57262506cb48787f68f809a13.png)

jmodeorain14

---

<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 23, 2023, 10:02am UTC](https://community.dynatrace.com/t/how-to-extract-values-from-response-body/32376/11 "2023-09-23T10:02:57Z")

</div>

Hi  
And where you put this code?
