List timeOff MSShift

danhol13 6 Reputation points
2022-09-09T06:15:35.86+00:00

If I run the function below, I'll only get the timeOff objects that start and end between $dateFrom and $dateTo. The problem is that I wont get the current "active" timeOffs, if say a timeOff object lasts the whole week, then it would currently be "active". So I want to be able to get those aswell. Cause now I will only get the timeOff objects that's "active" on that day, and not the ones that starts before and ends after. Is there any way to get those too?

Here's an example where two employees are sick more than one day, which my current API request won't get:
239306-image.png

    function Get-MgShiftTimeOffList {  
        param (  
            #Id of the Team to get shifts from  
            [Parameter(Mandatory)]$teamId,  
            #Id of the user that the request is sent on the behalf of  
            [Parameter(Mandatory)]$actAsUID,  
            #Timespan to fetch shifts from  
            [Parameter(Mandatory)][datetime]$dateFrom,  
            [datetime]$dateTo = $dateFrom.AddDays(1)  
        )  
      
        #Convert to "ISO 8601" date format, which is supported in json queries  
        $convertedDateFrom = [Xml.XmlConvert]::ToString($dateFrom,[Xml.XmlDateTimeSerializationMode]::Utc)  
        $convertedDateTo = [Xml.XmlConvert]::ToString($dateTo,[Xml.XmlDateTimeSerializationMode]::Utc)  
      
        $splat = @{  
            "Method" = "GET"  
            "Uri" = "https://graph.microsoft.com/v1.0/teams/$teamId/schedule/timesOff"  
            "Headers" = @{  
                "Authorization" = "Bearer $(Get-MgAccessToken)"  
                "MS-APP-ACTS-AS" = $actAsUID  
            }  
            "Body" = @{  
                '$filter' = "sharedTimeOff/startDateTime ge $convertedDateFrom and sharedTimeOff/endDateTime le $convertedDateTo"  
            }  
        }  
        Invoke-RestMethod @splat  
    }  
      
    Get-MgShiftTimeOffList -teamId (Redacted) -acAsUID (Redacted) -dateFrom (Get-Date "09/09/22 00:00")  
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,001 questions
{count} votes

1 answer

Sort by: Most helpful
  1. danhol13 6 Reputation points
    2023-04-20T06:40:47.06+00:00

    Regarding the initial question, I've been in contact with Microsoft support, and Microsoft's working on an option to get the currently active timeOff objects in some sort of filter for the API. It's not high priority, but it's atleast on their roadmap.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.