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(api.date(), "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"
}
]
},
Solved! Go to Solution.
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:
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(api.date(), "yyyy-MM-dd'T'HH:mm:ss"));
Please try and let us know.
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.