bookings-samples

Overview of the Microsoft Bookings API

The Microsoft Bookings API allows Office 365 Business Premium subscribers to manage their Bookings data using the Microsoft Graph.

Getting Started

In order to use the Bookings API you will need:

Authentication

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;

Client Libraries

.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());

Booking Entities, Operations and Permissions Scopes

For additional information about Booking entities, operations and permission scopes see the Microsoft Graph documentation.

See also: