Reporting web service client library
You can now use our new C# client library to build apps that export data from the Office 365 Reporting OData API, part of the Office 365 Reporting web service. This article explains how to add the client library to your app in Visual Studio and provides the code you need to call the web service and export your data.
Applies to: Office 365
In this article
Get started with the Office 365 reporting web service client library
Create a new project in Visual Studio 2013
Download the NuGet package
Run the code that calls the web service
Reports currently supported
Contribute to this project
Giving us feedback
Additional resources
Get started with the Office 365 reporting web service client library
The reporting web service client library is hosted in NuGet.org. You can start exporting your reporting data in minutes by using this new client library. Just follow these 3 simple steps:
Create a new project in Visual Studio
Download the NuGet package to get a reference to the reporting web service client library
Write the code that calls the web service
Create a new project in Visual Studio 2013
You can create a console application or Windows application project in C#. The following figure shows a standard C# console application project.
A console application in Visual Studio 2013
Download the NuGet package
Use the following procedure to download the NuGet package and get a reference to the reporting web service client library in Visual Studio:
Downloading the NuGet package
On the Tools menu in Visual Studio 2013, point to NuGet package manager, and then click Manage NuGet packages for Solution.
Click Online, and then select nuget.org.
In the search box, type "ReportingWebServiceClient."
In the Search Results list, click Install, click I Accept to accept the license terms, and then click Close to install the library in Visual Studio and get a reference to it in your project.
Your project will list a reference to the client library, as shown in the following image:
Project with reference to library
You are now ready to call the web service and export your data.
Run the code that calls the web service
Replace the default code in the Visual Studio project with the following code, and then run the project.
using Microsoft.Office365.ReportingWebServiceClient;
using System;
namespace O365ReportingDataExport
{
internal class Program
{
private static void Main(string[] args)
{
ReportingContext context = new ReportingContext();
//If you enter invalid authentication information, Visual Studio will throw an exception.
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 CustomConsoleLogger());
IReportVisitor visitor = new CustomConsoleReportVisitor();
ReportingStream stream1 = new ReportingStream(context, "MailboxUsageDetail", "stream1");
//Calls VisitReport
stream1.RetrieveData(visitor);
Console.WriteLine("Press Any Key...");
Console.ReadKey();
}
private class CustomConsoleLogger : ITraceLogger
{
public void LogError(string message)
{
Console.WriteLine(message);
}
public void LogInformation(string message)
{
Console.WriteLine(message);
}
}
private class CustomConsoleReportVisitor : 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());
}
}
}
}
Reports currently supported
The following report types are currently supported:
Client Software Browser Detail
Client Software OS Detail
Connection by Client Type*
Group Activity*
Mailbox Activity*
Mailbox Usage
OneDrive for Business user activity logs
OneDrive for Business sites deployed*
OneDrive for Business sites storage*
SharePoint Online Active User*
SharePoint Online team sites deployed*
SharePoint Online tenant storage metrics*
Stale Mailbox
Stale Mailbox Detail
Note
An asterisk (*) indicates report types for which daily, weekly, monthly, and yearly aggregates of the same report are provided separately. Not all report types have these four different aggregates.
Contribute to this project
This client library is an open source project under an MIT license, provided by Microsoft. It is available on github. We welcome contributions.
Giving us 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.