Query data from the Azure Time Series Insights Gen1 environment using C Sharp
Note
The Time Series Insights service will be retired on 7 July 2024. Consider migrating existing environments to alternative solutions as soon as possible. For more information on the deprecation and migration, visit our documentation.
Caution
This is a Gen1 article.
This C# example demonstrates how to use the Gen1 Query APIs to query data from Azure Time Series Insights Gen1 environments.
Tip
View Gen1 C# code samples at https://github.com/Azure-Samples/Azure-Time-Series-Insights.
Summary
The sample code below demonstrates the following features:
How to acquire an access token through Microsoft Entra ID using Microsoft.IdentityModel.Clients.ActiveDirectory.
How to pass that acquired access token in the
Authorization
header of subsequent Query API requests.The sample calls each of the Gen1 Query APIs demonstrating how HTTP requests are made to the:
- Get Environments API to return the environments the user has access to
- Get Environment Availability API
- Get Environment Metadata API to retrieve environment metadata
- Get Environments Events API
- Get Environment Aggregates API
How to interact with the Gen1 Query APIs using WSS to message the:
Prerequisites and setup
Complete the following steps before you compile and run the sample code:
- Provision a Gen1 Azure Time Series Insights environment.
- Configure your Azure Time Series Insights environment for Microsoft Entra ID as described in Authentication and authorization.
- Install the required project dependencies.
- Edit the sample code below by replacing each #DUMMY# with the appropriate environment identifier.
- Execute the code inside Visual Studio.
Project dependencies
It's recommended that you use the newest version of Visual Studio:
- Visual Studio 2019 - Version 16.4.2+
The sample code has two required dependencies:
- Microsoft.IdentityModel.Clients.ActiveDirectory - 3.13.9 package.
- Newtonsoft.Json - 9.0.1 package.
Download the packages in Visual Studio 2019 by selecting the Build > Build Solution option.
Alternatively, add the packages using NuGet 2.12+:
dotnet add package Newtonsoft.Json --version 9.0.1
dotnet add package Microsoft.IdentityModel.Clients.ActiveDirectory --version 3.13.9
C# sample code
Please refer to the Azure Time Series Insights] repo to access the C# sample code.
Next steps
To learn more about querying, read the Query API reference.
Read how to connect a JavaScript app using the client SDK to Time Series Insights.