← Return To Home

Search Logic Apps Run or Trigger History

Introduction

Logic Apps in real-time will define the business workflow. Searching for a specific Logic App run by its identifier or by start and end time is a critical requirement. This article would guide a developer implement searching Logic Apps run and trigger history by leveraging the Logic App SDK. If you are looking for out-of-the-box capability to access your Azure Logic Apps run and trigger history, then Serverless360 is the best solution.

What is a Logic App?

Logic App is an Azure offered cloud service which can connect business-critical apps and services to facilitate automating business workflows without writing a single line of code.

Every Logic App workflow starts with a trigger, which would fall under either of the following:

  • Polling triggers: Regularly checks a service endpoint for new data
  • Push triggers: Listens for data at a service endpoint and waits until a specific event happens 

The trigger defines the calls those instantiate and start the workflow to execute the actions defined.

Below are the key characteristics of Azure Logic Apps:

  • Follows workflow model
  • API as custom connectors
  • Simple and scalable

Accessing the trigger and run histories of Azure Logic Apps is the pre-requisite to search for a specific run. Let us now focus on retrieving the records consuming the exposed SDK’s.

Logic apps runs and trigger history

Required Packages

The following packages need to be installed in order to get the Logic App runs or triggers:

  • IdentityModel.Clients.ActiveDirectory
  • Rest.ClientRuntime
  • Azure.Management.Logic

Microsoft.IdentityModel.Clients.ActiveDirectory

This package contains the binaries of the Active Directory Authentication Library (ADAL). It provides an easy way to use authentication functionality for your .NET based client by taking advantage of Windows Server Active Directory and Azure Active Directory.

Microsoft.Rest.ClientRuntime

 Provides common Error Handling, Tracing, and HTTP/REST-based pipeline manipulation.

Microsoft.Azure.Management.Logic

 This SDK helps in managing Logic App. At this context, this SDK is used for retrieving the runs.

How to Access the Logic App?

In order to access, Logic App management client needs to be generated. The following credentials are required to get the Logic App management client.

  • Azure Subscription Id
  • Tenant Id
  • Azure Client Id
  • Azure Client Secret

Code Snippet to Generate Logic App Management Client

Tenant Id:  A Tenant is a representative of an organization within the Azure Active Directory. It is a dedicated instance of the Azure AD service.

Azure Client Id: Azure Active Directory application ID which provides access to the Azure resources.

Azure Client Secret: The Client Secret is a secret known only to the OAuthClient and the Authorization Server. Client Secret must be sufficiently random to not be guessable.

To access the resource, we need to provide contributor level of access to the Active Directory application.

In the above code, the Active Directory application acts as an authentication server which provides the access token to access the Logic App when we pole the Active Directory application with the Client ID and Client Secret.

Free download this blog as a PDF document for offline read.

How to Get Logic App Runs?

The Logic App management client should be provided with Logic App name and Resource Group name to get its runs.

odataQuery can be used to form query to retrieve runs based on the below parameters:

  • status
  • start time
var runs = await logicManagementClient.WorkflowRuns.ListAsync("Megahertz", "webshop", odataQuery);

“odataQuery.Filter” parameter can be used to perform a filtered search based on the query. Now to retrieve the Logic App runs. We need to pass on the Resource Group name, Logic App name and Search Query. This will return the run history based on the status and the start time provided.

Entire Code Snippet to Get the Logic App Runs

Output

This image depicts the output on running the above code sucessfully.

Azure Logic App Runs

The Filter Runs Based on the Status

To filter the runs based on the status “odataQuery.Filter” value should be provided.

Query filter should look something like this to retrieve succeeded runs:

odataQuery.Filter = "status eq ‘succeeded’"

There are 13 workflow status, some of them are:

  • Aborted
  • Canceled
  • Failed
  • Ignored
  • Succeeded
  • Running

Filter Runs Based on the Start Time

odataQuery.Filter =“ startTime ge <yyyy-MM-ddTHH:mm:ss.fffZ>”

Filter Runs Within a Time Frame

odataQuery.Filter = “ startTime ge <yyyy-MM-ddTHH:mm:ss.fffZ> and startTime le <yyyy-MM-ddTHH:mm:ss.fffZ>”

We can formulate queries based on the requirements.

Trigger History

We can also retrieve trigger history of the Logic Apps with this same SDK “Microsoft.Azure.Management.Logic” as below:

var runs = await logicManagementClient.WorkflowTriggerHistories.ListAsync(“<ResourceGroup>”,”<LogicAppName>”, “<triggerName>”, odataQuery);

Conclusion

In this blog, we saw how to retrieve run/trigger history of Azure Logic Apps and how to filter the workflow based on our requirements with various search queries.

Author: Priya Latha

Priya Latha is a Jr.Software Engineer at Kovai.co. She loves working with Angular, . Net and on Serverless technologies. She believes in the quote that "Expect nothing less than perfect".