Client library for Office 365 admin reporting web service now available

Julien Pierre is a program manager and Toney Sui is a software engineer with the Office big data team in Beijing, China.

If your company has deployed Office 365 and it has a central monitoring solution that enables you to continually look at the health of your IT services in one unified place—such as a help desk, reporting dashboard or other solution—there’s good news. Developers and independent software vendors (ISV) with a central monitoring solution like this can now use that solution to monitor Office 365 along with your other IT services, using the OData API. This new client library, the Office 365 Reporting Web Service Client Library, is available in .NET and makes it easier to export reporting data.

The library is available on nuget.org.

Client library for Office 365 1

The client library simplifies access to the API

Office 365 provides a REST-based API that enables developers to access their tenant admin reports’ data, such as OneDrive for Business user activity logs, a range of Exchange- and Lync-related reports, and more. You can code directly against the REST API to fetch data and perform simple queries. However, it requires a specific logic in order to properly fetch a complete data set, especially when you’re dealing with potentially hundreds of thousands of records for certain reports, constructing the right URLs and maintaining data integrity on the target store. By using this client library to access the Office 365 Reporting web service, you can reduce the complexity of code you need to write to access the API. We are providing this library for .NET only.

With this client library, you can:

  • Fetch data from a report.
  • Specify a date range for target querying.
  • Remember the last record you fetched for continuous data exporting.
  • Implement your own record and trace logger processor.

For example, here’s the .NET C# code to fetch the mailbox usage detail report:

using Microsoft.Office365.ReportingWebServiceClient;
using System;
 
namespace O365ReportingDataExport
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            ReportingContext context = new ReportingContext();
            context.UserName = @"PUT YOUR OFFICE 365 USER EMAIL ADDRESS HERE";
            context.Password = @"PUT YOUR OFFICE 365 USER PASSWORD HERE";
            //FromDateTime & ToDateTime are optional, default value is DateTime.MinValue if not specified
            context.FromDateTime = DateTime.MinValue;
            context.ToDateTime = DateTime.MinValue;
            context.SetLogger(new MyLogger());
 
            IReportVisitor visitor = new MyReportVisitor();
 
            ReportingStream stream1 = new ReportingStream(context, "MailboxUsageDetail", "stream1");
            stream1.RetrieveData(visitor);
 
            Console.WriteLine("Press Any Key...");
            Console.ReadKey();
        }
 
        private class MyLogger : ITraceLogger
        {
            public void LogError(string message)
            {
                Console.WriteLine(message);
            }
 
            public void LogInformation(string message)
            {
                Console.WriteLine(message);
            }
        }
 
        private class MyReportVisitor : IReportVisitor
        {
            public override void VisitBatchReport()
            {
                foreach (ReportObject report in this.reportObjectList)
                {
                    VisitReport(report);
                }
            }
 
            public override void VisitReport(ReportObject record)
            {
                Console.WriteLine("Record: " + record.Date.ToString());
            }
        }
    }
}

If you do not specify a From/To date time, the first query will try to fetch the earliest top 1000 records and gradually fetch all the data in chunks of 1000.

Client library for Office 365 2

Running the code sample above in Visual Studio 2013.

For each record retrieved from the API, the client library goes through the VisitReport method, which enables you to process the record the way you want, for example, by saving it to a .csv file, third-party Business Intelligence software, or a SQL Server database.

Client library for Office 365 3

Exploring a record’s properties in Visual Studio 2013.

Reports currently supported by the client library

The reports currently supported are:

  • GroupActivity
  • GroupActivityDaily
  • GroupActivityMonthly
  • GroupActivityWeekly
  • GroupActivityYearly
  • MailboxActivity
  • MailboxActivityDaily
  • MailboxActivityMonthly
  • MailboxActivityWeekly
  • MailboxActivityYearly
  • MailboxUsage
  • MailboxUsageDetail
  • StaleMailbox
  • StaleMailboxDetail 

You can find more information on the all the reports available to admins in the Office 365 reporting web service.

Note: Your Office 365 subscription might not include all of the reports listed above. To see which reports are part of your subscription, check the Reports section of Office 365 in your Office 365 admin center.

Feedback

Have questions? Connect with us on StackOverflow. Tag your question with [O365RwsClient].

Be sure to also connect with the team on the Office 365 Technical Network on Yammer.

Your feedback about this library is important to us.

—Julien Pierre