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

HTTP Requests --> Script mode How can I add date variable in HTTP Get request


I have this request and I want to use pick current date every time instead of hardcoding this value, I tried using api.setValue("currentDate", api.dateToFormat(, "dd/MM/yy")); but its giving syntax error.


Please let me know how can I achive this, basically in from and to in below URL I want it to pick current date everytime.

"version": "1.0",
"requests": [
"description": "dev.testazure.test/test-service",
"url": "https://dev.testazure.test/test-service/api/v1/eventhistory/notification?from=2022-09-12T04:35:51-04...",
"method": "GET",
"validation": {
"rules": [
"value": ">=400",
"passIfFound": false,
"type": "httpStatusesList"


DynaMight Guru
DynaMight Guru

Hi @vabg , good day.

To achieve this, you first need to set the variable in pre-execution script, and then refer the variable in the URL, like this:

Screen Shot 2022-10-18 at 09.11.28.png

you can add any number of variables there to replace your requests params according.


Also, do confirm the proper date format syntax, and use this to get the right one.


based on the example you sent, your pre-execution script would be like:


api.setValue("dateToFormatCurrentDate", api.dateToFormat(, "yyyy-MM-dd'T'HH:mm:ss"));


Please try and let us know.

Site Reliability Engineer @ Kyndryl


Hi @dannemca 

Thanks for your help, its working fine.

Could you please also let me know if we have any method to return previous day date like return present date



DynaMight Guru
DynaMight Guru

You can "go crazy" using pre/post-execution script. You can do some math and calculate the previous date based on current date. It may requires some scripting skills, but doable.

Also, do check if the API you are calling does allow you to transform the date interval, like Dynatrace API does, example, "from=-24h to now", means all previous 24h.

Site Reliability Engineer @ Kyndryl

Featured Posts