When it comes to Microsoft Bookings and automation the documentation about API can be found here, there is also a PowerShell module, at first I didn’t know how to connect to Bookings API and I’ve created a booking mailbox with Exchange Online PowerShell with New-SchedulingMailbox BUT! do not do it.
This New-SchedulingMailbox is not a good way to create it – later I had some issues when I was trying to do changes on the booking resource using API, see here and here.
Ther code to connect to the API is:
$TenantID = "<tenant>.onmicrosoft.com" $AccountName = "BookingAutomation@domain.com" $Password = '<bookingautomationpassword>' $ClientId = "XXXXXXX-XXX-XXX-XXX-XXXXXXXXXXXXX" # "Booking-GraphAPI" application ID</bookingautomationpassword></tenant> # Constants - Endpoints $AzureResourceURI = "https://login.microsoftonline.com/$($tenantID)/oauth2/token" $ResourceID = "https://graph.microsoft.com" # Construct the Body for the POST $Body = "grant_type=password"` +"&username=" +$Accountname ` +"&client_id=" +$clientId ` +"&password=" +$Password ` +"&resource=" +[system.uri]::EscapeDataString($ResourceID) Write-Host "Getting the authorization token" # The result should contain a token for use with Graph $Response = Invoke-WebRequest -Uri $AzureResourceURI -Method POST -Body $Body $ResponseJSON = $Response|ConvertFrom-Json
After connectig you can use this to create a Booking with PowerShell module:
$NewBookingParams = @{ DisplayName = "FirstBooking" BusinessType = "IT Services" WebSiteUrl = "https://www.domain.com" SchedulingPolicy = @{ AllowStaffSelection = $false MaximumAdvance = "P30D" MinimumLeadTime = "P1D" } } $NewBooking = New-MgBookingBusiness @NewBookingParams
Adding users is easy, so I will just share a way I am creating a service:
$NewServiceParams = @{ BookingBusinessId = $PrimarySmtpAddress DefaultDuration = "00:15:00" # 15 minutes duration IsLocationOnline = $true MaximumAttendeesCount = 10 StaffMemberIds = $StaffMemberId #A staff member ID to be assigned to the service DisplayName = "15 min call" DefaultReminders = @{ Message = "Just a quick reminder that your service is comming up soon." Offset = "P1D" #0 - All recipients, 2 - Customer, 1 - Staff Recipients = "2" } } New-MgBookingBusinessService @NewServiceParams