Can we create Availability web test in application insights by using API Key in C#?

Rajkumar Yergamoni 26 Reputation points
2020-12-02T13:17:14.25+00:00

If Yes, What is the procedure.

Am able to get the event details by using the Application insights API key and API Id, but not able to create the web test.

Ref URL: https://dev.applicationinsights.io/documentation/Using-the-API/Events

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,812 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,913 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ryan Hill 25,981 Reputation points Microsoft Employee
    2020-12-02T17:04:12.823+00:00

    Hi @Rajkumar Yergamoni ,

    If I'm understanding you correctly, you would like to use an C# application to create an Availability test. If correct, I would suggest using the Azure Management SDK to create the test. It's not straight forward, but you should be able to use ApplicationInsightsComponent class to create the resource similar to https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/applicationinsights/Microsoft.Azure.Management.ApplicationInsights/tests/ScenarioTests/ComponentsTests.cs.

    ApplicationInsightsComponent bodyParameter = new ApplicationInsightsComponent(  
                    name: nameof(CreateGetListUpdateDeleteAPIKeys),  
                    location: "South Central US",  
                    kind: "web",  
                    applicationType: "web",  
                    applicationId: nameof(CreateGetListUpdateDeleteAPIKeys),  
                    flowType: "Bluefield",  
                    requestSource: "rest");  
      
    var insightsClient = new ApplicationInsightsManagementClient(...);  
      
    //"create new component";  
    var createdComponentResponse = insightsClient  
                                        .Components  
                                        .CreateOrUpdateWithHttpMessagesAsync(  
                                            ResourceGroupName,  
                                            nameof(CreateGetListUpdateDeleteComponents),  
                                            insightProperties: bodyParameter)  
                                        .GetAwaiter()  
                                        .GetResult();  
    

    This quick start guide will be helpful in initializing your client.

    EDIT: You can't use the Application Insights API to create tests. That's not what it was designed for, see https://dev.applicationinsights.io/reference. There are only 2 endpoints designated for POST'ing and those methods are for data retrieval. If you were to review the network traffic (your browser developer tools), you would see that when you create the test, requests to the https://management.azure.com. The SDK I provided above is an easier way to make those rest calls to Azure REST API.

    Regards,
    Ryan

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful