Dashboard API multiple parameters besides queryId
Hi,
is there a way to send parameters like a date, a string etc to have the sql queries in the dashboard api more dynamic. For example i want to see all my tickets from the last 5 days.
Best Answers
-
Justin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
There absolutely is!
Are you talking about just using the API? If so, you can provide tokens to the api call. For example:
$.get('/api/V3/Dashboard/GetDashboardDataById?queryId=540e2d61-4b6c-43d5-8d58-b60f11fdf3fe&myDateRange=5', function(response) {
// do something with the dashboard data here
})
And the query behind would look like this:
SELECT WorkItemId, Title
FROM WorkItem
WHERE AffectedUserId = @UserId -- this token represents the logged in user's Id
AND CreatedDate > dateadd(DAY, -{{myDateRange}}, GetDate()) --the {{myDateRage}} token gets replaced with the 5 from the api call
2 -
Adam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭
I have 100% done this when I integrated SCOM statistics into the CMDB portal which you can check out over here.
1
Answers
There absolutely is!
Are you talking about just using the API? If so, you can provide tokens to the api call. For example:
$.get('/api/V3/Dashboard/GetDashboardDataById?queryId=540e2d61-4b6c-43d5-8d58-b60f11fdf3fe&myDateRange=5', function(response) {
// do something with the dashboard data here
})
And the query behind would look like this:
SELECT WorkItemId, Title
FROM WorkItem
WHERE AffectedUserId = @UserId -- this token represents the logged in user's Id
AND CreatedDate > dateadd(DAY, -{{myDateRange}}, GetDate()) --the {{myDateRage}} token gets replaced with the 5 from the api call
I have 100% done this when I integrated SCOM statistics into the CMDB portal which you can check out over here.
@Justin_Workman and @Adam_Dzyacky thank you for the information. :-)
It would be nice if these important informations would be in the API Documentation.
And one more question about these parameters. How to pass datetime with these parameters? In which format datetime must be converted to work. for example "2022-01-01" ?
@Jan_Schulz - Any date format will go, it just depends on how SQL interprets it.