Home Analyst Portal

Dashboard API multiple parameters besides queryId

Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

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_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    Answer ✓

    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

  • Adam_DzyackyAdam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭
    edited March 1 Answer ✓

    I have 100% done this when I integrated SCOM statistics into the CMDB portal which you can check out over here.

Answers

  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    Answer ✓

    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

  • Adam_DzyackyAdam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭
    edited March 1 Answer ✓

    I have 100% done this when I integrated SCOM statistics into the CMDB portal which you can check out over here.

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

    @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" ?

  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭

    @Jan_Schulz - Any date format will go, it just depends on how SQL interprets it.

Sign In or Register to comment.