Possible bug/documentation error in Shifts TimeOff Creation

Steven Bailey 0 Reputation points
2023-05-26T15:57:46.8533333+00:00

Hello,

I am working with auto-creation of TimeOff requests in Shifts (straight push, no approval step), and I think I've run either into a bug or an error/lack of clarity in the documentation. The documentation here (https://learn.microsoft.com/en-us/graph/api/schedule-post-timesoff?view=graph-rest-1.0&tabs=http) shows the example to have both the draftTimeOff and sharedTimeOff specified in the creation request, but when I actually try to execute this in PowerShell, I get the following error:
User's image

That error message indicates I can't have both the draftTimeOff and sharedTimeOff segment specified in this request, which contradicts the documentation. I am able to run the call fine if I do either draftTimeOff or sharedTimeOff by itself, and I see also another available command to approve a drafted timeOff request here (https://learn.microsoft.com/en-us/graph/api/timeoffrequest-approve?view=graph-rest-1.0&tabs=http). I'm just looking for clarification on what the correct call/process should be in this case.

Code below in case that is relevant:

###############
$User = UPN of targeted user
$TimeOff = The TimeOffReason object already pulled from Shifts via Graph
* The .AddHours is for time zone adjustments
###############

$timeOffBody = @{
        userId = (Get-MgUser -UserId $User).Id
        sharedTimeOff = @{
            timeOffReasonId = $TimeOff.id
            startDateTime = $StartDate.AddHours(-1).ToString("yyyy-MM-ddTHH:mm:ssZ")
            endDateTime = $EndDate.AddHours(23).ToString("yyyy-MM-ddTHH:mm:ssZ")
            theme = "blue"
        }
        draftTimeOff = @{
            timeOffReasonId = $TimeOff.id
            startDateTime = $StartDate.AddHours(-1).ToString("yyyy-MM-ddTHH:mm:ssZ")
            endDateTime = $EndDate.AddHours(23).ToString("yyyy-MM-ddTHH:mm:ssZ")
            theme = "blue"
        }
    } | ConvertTo-Json

    Invoke-MgGraphRequest -Method POST -Uri https://graph.microsoft.com/v1.0/teams/$TeamId/schedule/timesOff -Body $timeOffBody -ContentType application/json -Headers @{ "MS-APP-ACTS-AS" = "$((Get-MgContext).Account)" }
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Your answer

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