azure-logic-appsazure-management-api

simplest way to access logic app workflow history via management.azure.com API


I need to access logic app history. My understanding is this needs to be done via the azure management api:

API URL: GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{workflowName}/triggers/{triggerName}/histories/{historyName}?api-version=2016-06-01

What is the best way to do this:

Appreciate any expertise and advice.


Solution

  • This is a basic C# implementation of the SDK to retrieve the run history which is developed in VS2022. The authentication is done via the user that is logged into Azure from VS.

    Authentication

    Read here for other options on authenticating to the subscription ...

    https://learn.microsoft.com/en-gb/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet

    Be sure to install the following nuget packages ...

    This is the sample program ...

    using Azure.Identity;
    using Azure.ResourceManager;
    using Azure.ResourceManager.Logic;
    using System;
    using System.Threading.Tasks;
    
    namespace AzureManagement
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                GetLogicApps().Wait();
            }
    
            static async Task GetLogicApps()
            {
                // Authenticate and create the ArmClient instance.
                var credential = new DefaultAzureCredential();
                var armClient = new ArmClient(credential);
                var subscription = await armClient.GetDefaultSubscriptionAsync();
    
                // Get all LogicApps.
                var logicAppsEnumerator = subscription.GetLogicWorkflowsAsync().GetAsyncEnumerator();
    
                try
                {
                    while (await logicAppsEnumerator.MoveNextAsync())
                    {
                        // For the current LogicApp, retrieve its run history.
                        var logicApp = logicAppsEnumerator.Current;
                        Console.WriteLine(logicApp.Data.Name);
    
                        var logicAppRuns = logicApp.GetLogicWorkflowRuns();
    
                        foreach (var logicAppRun in logicAppRuns)
                        {
                            Console.WriteLine($"... Start DateTime = {logicAppRun.Data.StartOn}, End DateTime = {logicAppRun.Data.EndOn}, Status = {logicAppRun.Data.Status}");
                        }
                    }
                }
                finally
                {
                    await logicAppsEnumerator.DisposeAsync();
                }
    
                Console.Read();
            }
        }
    }
    

    If you need examples of how to use the SDK then start from here ...

    https://github.com/Azure/azure-sdk-for-net/blob/Azure.ResourceManager_1.3.1/sdk/resourcemanager/Azure.ResourceManager

    Samples aren't far and wide but there is enough information to be dangerous. Once you authenticate, you just need to have the relevant nuget package installed to access the different types of resources.