11 Aug 2021 08:15 PM - edited 11 Aug 2021 08:20 PM
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 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 response.getResponseBody() , how can we extract a value after token=" till the next " from the response body?
Thanks in advance
Yos
Solved! Go to Solution.
12 Aug 2021 12:46 PM
Hello
I think it's possible using Request Attributes
More details here Request Attributes
12 Aug 2021 02:19 PM
Hi @Malaik
Question is about post-execution script in http monitor.
How can we implement RA in http monitor?
Yos
12 Aug 2021 03:43 PM
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
12 Aug 2021 04:37 PM
Great , will give it a try next week at customer site and will update !
Thanks a lot
Yos
22 Apr 2022 01:43 PM
Hi @Yosi_Neuman!
I'm curious how this issue has ended eventually, were you able to find a desired solution as promised last year? 😄
Best regards!
22 Apr 2022 04:05 PM
As far as I remember it works OK.
I have accepted @alvaro_sanchez answer as a solution and sorry for the "slight" delay in doing that
Yos
15 Nov 2022 08:23 PM
I can confirm that you can use regex in the post-execution synthetic script. Here is who I did it for our application.
14 Sep 2023 09:44 AM
Hi,
I'm trying to capture a specific value from the response of a HTTP (API) request.
I have tried the approaches suggested by @alvaro_sanchez and @jkinner 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
22 Sep 2023 09:01 AM - edited 22 Sep 2023 09:02 AM
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
23 Sep 2023 11:02 AM
Hi
And where you put this code?