-
- Influencer
- Posts: 14
- Liked: 3 times
- Joined: Jan 14, 2021 8:01 am
- Full Name: Umesh Phendarkar
- Contact:
How to Specify last 24 Hours Timeline as Variable in Restapi Query ?
How to Specify last 24 Hours Timeline as Variable in Restapi Query ? Or Filter jobs by last 24 hours ?
-
- Veteran
- Posts: 1143
- Liked: 302 times
- Joined: Apr 27, 2020 12:46 pm
- Full Name: Natalia Lupacheva
- Contact:
Re: How to Specify last 24 Hours Timeline as Variable in Restapi Query ?
Hi Umesh,
You can specify the time period for your request in the filter parameter as we discussed.
Do you trigger the requests manually?
Query will not accept some variable as a value of EndTime. I believe the easiest way is to trigger the request with some script. The script will have to calculate EndTime, create a query and send the request.
(For example, you trigger the request each 24 hours and fill EndTime with <now()-24h> value).
Thanks!
You can specify the time period for your request in the filter parameter as we discussed.
Do you trigger the requests manually?
Query will not accept some variable as a value of EndTime. I believe the easiest way is to trigger the request with some script. The script will have to calculate EndTime, create a query and send the request.
(For example, you trigger the request each 24 hours and fill EndTime with <now()-24h> value).
Thanks!
-
- Influencer
- Posts: 14
- Liked: 3 times
- Joined: Jan 14, 2021 8:01 am
- Full Name: Umesh Phendarkar
- Contact:
Re: How to Specify last 24 Hours Timeline as Variable in Restapi Query ?
Thanks Natalia, When i mention the todays date, it works , however i do not still understand how i can mention 24 hours time in query. Since i have to run the script daily. I do not want to mention particular date every time manually. Any explanation for mentioning 24 hours time will be helpful for me.
Thanks..
Thanks..
-
- Veeam Software
- Posts: 2010
- Liked: 670 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: How to Specify last 24 Hours Timeline as Variable in Restapi Query ?
Hi Umesh,
As Natalia mentioned, you'll need to calculate datetime primarily to the request. Use Date built-in class, setHours() method and then string interpolation to insert the value you calculated into the query. The syntax per language may differ, but algorithm is the same.
For Javascript I do something like that:
Thanks,
Oleg
As Natalia mentioned, you'll need to calculate datetime primarily to the request. Use Date built-in class, setHours() method and then string interpolation to insert the value you calculated into the query. The syntax per language may differ, but algorithm is the same.
For Javascript I do something like that:
Code: Select all
const request = require('request');
let sessionId = 'YjRkMmRlMTctZjBmMy00MzdkLTlhMmQtZjEyODBjMjI5ZjEx';
let currentDate = new Date();
currentDate.setHours(-24);
let dateString = currentDate.toISOString();
let hostAddress = 'em-host';
let url = `https://${hostAddress}/api/query?type=BackupJobSession&format=Entities&sortAsc=name&pageSize=15&page=1&filter=EndTime>="${dateString}";Result==failed`;
let options = {
'method': 'GET',
'url': url,
'headers': {
'Accept': 'application/json',
'Cookie': `X-RestSvcSessionId=${sessionId}`
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
Oleg
-
- Influencer
- Posts: 14
- Liked: 3 times
- Joined: Jan 14, 2021 8:01 am
- Full Name: Umesh Phendarkar
- Contact:
Re: How to Specify last 24 Hours Timeline as Variable in Restapi Query ?
So this thing will work for searching for last 24hour data:-
timeend=$(date --date="-1 days" +%FT%TZ)
veeamEMUrl="https://YourVeeamUrl:9398/api/query?for ... t==Success"
And it will send response as :-
"EndTimeUTC": "2021-01-29T03:30:56.16Z",
"Result": "Success",
"EndTimeUTC": "2021-01-29T03:28:48.813Z",
"Result": "Success",
"EndTimeUTC": "2021-01-29T03:23:50.507Z",
"Result": "Success",
timeend=$(date --date="-1 days" +%FT%TZ)
veeamEMUrl="https://YourVeeamUrl:9398/api/query?for ... t==Success"
And it will send response as :-
"EndTimeUTC": "2021-01-29T03:30:56.16Z",
"Result": "Success",
"EndTimeUTC": "2021-01-29T03:28:48.813Z",
"Result": "Success",
"EndTimeUTC": "2021-01-29T03:23:50.507Z",
"Result": "Success",
Who is online
Users browsing this forum: No registered users and 1 guest