List timeOff MSShift

danhol13 6 Reputation points

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:

    function Get-MgShiftTimeOffList {  
        param (  
            #Id of the Team to get shifts from  
            #Id of the user that the request is sent on the behalf of  
            #Timespan to fetch shifts from  
            [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" = "$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 Teamwork API
{count} votes

1 answer

Sort by: Most helpful
  1. danhol13 6 Reputation points

    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