18 Oct 2022 12:01 PM
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.
18 Oct 2022 01:13 PM - edited 18 Oct 2022 01:18 PM
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.
18 Oct 2022 03:43 PM
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 api.date return present date
Thanks
18 Oct 2022 05:55 PM
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.