The Microsoft Bookings API allows Office 365 Business Premium subscribers to manage their Bookings data using the Microsoft Graph.
In order to use the Bookings API you will need:
-
An Office 365 Business Premium tenant in which you can create users and Bookings resources.
You can create a trial tenant by going to products.office.com, click Buy now with Office 365 and select Free Trial. -
You'll need to register client applications in Azure Active Directory and request permissions to call Bookings using Graph.
- Open https://portal.azure.com then go to Active Directory->App Registrations
- Create a new application and take note of its Application ID and Redirect Uri.
- Edit the settings of the application. Under 'Required Permissions', add API access to 'Microsoft Graph' and select 'Manage bookings information'.
-
Clone the bookings-samples repository and update your local copy with the Application ID and Redirect Uri of your Azure AD application.
Applications that wish to access the Bookings API must acquire tokens to communicate with Graph. The access token used with the API must contain the identity of an Office 365 user with subscriptions and permissions to use Bookings.
NOTE: at the time of this writing, the Bookings API does NOT support application-only permissions.
An example for obtaining a token in a native C# application using Active Directory Authentication Libraries (ADAL) goes like this:
var clientApplication = PublicClientApplicationBuilder.Create(clientApplicationAppId)
.WithAuthority(AadAuthorityAudience.AzureAdMyOrg)
.WithTenantId(tenantId)
.Build();
Console.Write("Username: ");
string username = Console.ReadLine();
if (string.IsNullOrEmpty(username))
{
Console.WriteLine("Update Sample to include your username");
return;
}
Console.Write("Password: ");
SecureString password = new SecureString();
ConsoleKeyInfo keyinfo;
do
{
keyinfo = Console.ReadKey(true);
if (keyinfo.Key == ConsoleKey.Enter) break;
password.AppendChar(keyinfo.KeyChar);
} while (keyinfo.Key != ConsoleKey.Enter);
if (password.Length == 0)
{
Console.WriteLine("Password needs to be provided for the sample to work");
return;
}
var authenticationResult = clientApplication.AcquireTokenByUsernamePassword(
new[] { "Bookings.Read.All" },
username, password).ExecuteAsync().Result;
.Net applications can then use ODATA v4 client-side proxy classes, such as the ones provided by the Microsoft ODATA Stack.
The bookings-samples repository contains such a generated client library, with just the types needed to access Bookings.
With it, a C# application can initialize a GraphService
with code like this:
var graphService = new GraphService(
GraphService.ServiceRoot,
() => authenticationResult.CreateAuthorizationHeader());
For additional information about Booking entities, operations and permission scopes see the Microsoft Graph documentation.
See also: