Bookings, GraphAPI, Powershell

Microsoft Bookings API how to

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>"
$AccountName    = ""
$Password       = '<bookingautomationpassword>'
$ClientId       = "XXXXXXX-XXX-XXX-XXX-XXXXXXXXXXXXX" # "Booking-GraphAPI" application ID</bookingautomationpassword></tenant>

# Constants - Endpoints
$AzureResourceURI = "$($tenantID)/oauth2/token"
$ResourceID  = ""

# Construct the Body for the POST
$Body = "grant_type=password"`
         +"&amp;username=" +$Accountname `
         +"&amp;client_id=" +$clientId `
         +"&amp;password=" +$Password `
         +"&amp;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 = ""
    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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s