Microsoft Sentinel
Cloud and workloads

Update Logic App playbook automation - Microsoft Sentinel | Microsoft Learn

In brief

A new article explains how to update playbooks that query Log Analytics or Azure Monitor Logs to use Microsoft Defender XDR Advanced Hunting through Microsoft Graph, including query, table, timestamp, and response-format changes.

What Defender admins need to know

Administrators performing the transition must update affected playbooks and provide an approved identity with ThreatHunting.Read.All permission and admin consent.

Summaries are generated from the documentation change itself.

Documentation change

The comparison below shows only the changed extract. Use the full-page view for complete context.

new file mode 100644

layout: Conceptual title: Update Logic App playbook automation - Microsoft Sentinel | Microsoft Learn canonicalUrl: https://learn.microsoft.com/en-us/azure/sentinel/transition-logic-app-playbooks breadcrumb_path: breadcrumb/toc.json feedback_help_link_url: https://learn.microsoft.com/answers/tags/423/microsoft-sentinel/ feedback_help_link_type: get-help-at-qna feedback_product_url: https://feedback.azure.com/d365community/forum/79b1327d-d925-ec11-b6e6-000d3a4f06a4 feedback_system: Standard learn_banner_products:


Update Logic App playbook automation - Microsoft Sentinel | Microsoft Learn

When you transition Microsoft Sentinel content from workspace-based data to Microsoft Defender XDR Advanced Hunting data, update Logic App playbooks that run Log Analytics queries so that they query Advanced Hunting instead.

The update changes the query data source and response format while preserving the rest of the automation flow where possible. Typically, the playbook trigger and downstream enrichment, notification, or response actions remain the same.

Note

This article applies to Logic App playbooks that query Log Analytics or Azure Monitor Logs. It doesn't describe the migration of automation rules associated with Microsoft Sentinel analytics rules. For analytics rule migration, see Convert Microsoft Sentinel analytics rules to custom detections.

For changes to KQL table names, time columns, and data types, see Update Microsoft Sentinel content to use Advanced Hunting tables.

Understand the playbook changes

The following table summarizes the main changes when you update a playbook to use Advanced Hunting.

Current implementationTarget implementation
Log Analytics or Azure Monitor Logs connectorMicrosoft Graph API call to Advanced Hunting
Workspace-based Microsoft Sentinel or Log Analytics tablesMicrosoft Defender XDR Advanced Hunting tables
Queries that use TimeGeneratedAdvanced Hunting queries that use Timestamp
Response parsing from the existing query action's outputResponse parsing from schema and results

The updated playbook flow is:

  1. Start from the existing Logic App trigger.
  2. Initialize or compose the Advanced Hunting query.
  3. Call Microsoft Graph by using POST /security/runHuntingQuery.
  4. Parse the response body.
  5. Loop over the results array.
  6. Run the existing enrichment, notification, or response actions.

Prerequisites

Before you update a Logic App playbook, make sure that the following requirements are met.

RequirementDetails
Microsoft Defender XDR accessAdvanced Hunting data must be available in Microsoft Defender XDR.
Logic App identityUse a system-assigned managed identity, user-assigned managed identity, or application registration.
Microsoft Graph permissionGrant ThreatHunting.Read.All. Admin consent is required.
Query validation accessAn administrator or analyst must be able to validate each query in Advanced Hunting in the Microsoft Defender portal.
Change controlTest the changes in a nonproduction or cloned playbook before replacing production actions.

Before you update a production playbook, confirm table availability, permissions, and query behavior in your tenant.

Configure permissions and authentication

The Advanced Hunting API requires the ThreatHunting.Read.All Microsoft Graph permission.

Permission typePermissionRecommended use
ApplicationThreatHunting.Read.AllRecommended for production Logic App automation.
DelegatedThreatHunting.Read.AllUseful for user-context testing or interactive scenarios.

Use a managed identity where possible.

If you use an HTTP action, configure it with the following settings:

SettingValue
Authentication typeManaged Identity
IdentitySystem-assigned or user-assigned managed identity
Audiencehttps://graph.microsoft.com
HTTP methodPOST
URIhttps://graph.microsoft.com/v1.0/security/runHuntingQuery

If you use a Microsoft Graph connector or custom connector instead of the generic HTTP action, configure it to call the same endpoint with the required permissions and request body.

Call the Advanced Hunting API

Use the following Microsoft Graph endpoint:

POST https://graph.microsoft.com/v1.0/security/runHuntingQuery

The request uses the following headers:

Content-Type: application/json
Authorization: Bearer <token>

For example:

{
  "Query": "DeviceProcessEvents | where Timestamp > ago(1h) | take 100"
}

You can also specify an explicit timespan:

{
  "Query": "DeviceProcessEvents | project Timestamp, DeviceName, FileName, ProcessCommandLine",
  "Timespan": "PT1H"
}

The Timespan parameter is optional. You can also restrict the time range directly in the KQL query. If both are used, the narrower time range applies.

Update a Logic App playbook

Update each playbook that runs queries against Log Analytics, Azure Monitor Logs, or workspace-based Microsoft Sentinel data.

  1. Identify every Logic App action that uses Log Analytics, Azure Monitor Logs, or workspace-based query execution.

  2. Copy the existing KQL query and identify which output columns are used by downstream actions.

  3. Map the Log Analytics tables and columns to their Advanced Hunting equivalents.

    For table and schema changes, see Update Microsoft Sentinel content to use Advanced Hunting tables.

  4. Replace TimeGenerated filters with Timestamp, where applicable.

  5. Validate the updated KQL query in Advanced Hunting in the Microsoft Defender portal.

  6. Replace the Log Analytics query action with a Microsoft Graph call to:

    /security/runHuntingQuery
    
  7. Update response parsing to use the results array.

  8. Update downstream expressions to use named JSON properties instead of row indexes, where applicable.

  9. Add handling for empty results and API errors.

  10. Test the playbook end to end before enabling the updated version in production.

Map commonly used tables

The following table provides examples of Advanced Hunting tables commonly used by playbooks.

DataAdvanced Hunting tableNotes
Defender XDR alert metadataAlertInfoAlert title, severity, category, service source, and alert ID
Alert entities or evidenceAlertEvidenceRelated users, devices, files, URLs, IP addresses, and evidence
Device process activityDeviceProcessEventsProcess creation and related endpoint process events
Device network activityDeviceNetworkEventsInbound and outbound network connection events
Device file activityDeviceFileEventsFile creation, modification, and file-system events
Device registry activityDeviceRegistryEventsRegistry creation, modification, and deletion events
Device logon activityDeviceLogonEventsDevice authentication and logon events
Email eventsEmailEventsEmail delivery and message metadata
Email attachmentsEmailAttachmentInfoAttachment metadata for email messages
Email URLsEmailUrlInfoURLs observed in email messages
Post-delivery email actionsEmailPostDeliveryEventsPost-delivery actions, such as zero-hour auto purge (ZAP)
Cloud app activityCloudAppEventsCloud application and SaaS activity
Identity informationIdentityInfo or IdentityAccountInfoValidate the table available in your tenant
Microsoft Entra ID sign-in eventsEntraIdSignInEvents or AADSignInEventsBetaUse the table available in your Advanced Hunting schema

Table and column availability can vary based on licensing, tenant configuration, data-source onboarding, and schema changes. Validate the required tables in your tenant before updating a production playbook.

Update response parsing

Log Analytics response formats depend on how the playbook runs the query. Azure Monitor Logs and Azure Log Analytics listing actions, including their deprecated versions, return a value array of objects with named fields. Direct Log Analytics query REST calls return tables and positional row arrays. Microsoft Graph Advanced Hunting returns schema and results.

Change the loop input to results. Replace positional field references with named properties where used. If expressions already use named properties, update only those affected by changes to the query output.

The following examples apply to playbooks that read tables[0].rows. They assume that the first two source columns map to Timestamp and DeviceName. Apply the same approach to every field the playbook uses.

Log Analytics patternAdvanced Hunting pattern
body('Run_query')?['tables'][0]?['rows']body('Run_Hunting_Query')?['results']
items('For_each')?[0]items('For_each')?['Timestamp']
items('For_each')?[1]items('For_each')?['DeviceName']

An Advanced Hunting response can look like the following example:

{
  "schema": [
    {
      "name": "Timestamp",
      "type": "DateTime"
    },
    {
      "name": "DeviceName",
      "type": "String"
    },
    {
      "name": "FileName",
      "type": "String"
    }
  ],
  "results": [
    {
      "Timestamp": "2026-06-23T08:00:00Z",
      "DeviceName": "device01.contoso.com",
      "FileName": "powershell.exe"
    }
  ]
}

Parse the response

Add a Parse JSON action after the Microsoft Graph call.

You can use the following schema as a starting point:

{
  "type": "object",
  "properties": {
    "schema": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string"
          }
        }
      }
    },
    "results": {
      "type": "array",
      "items": {
        "type": "object"
      }
    }
  }
}

Configure the For each action to iterate over:

body('Parse_JSON')?['results']

Update common playbook queries

The following examples show how common Log Analytics queries can be updated to use Advanced Hunting.

Alert enrichment

A Log Analytics query might use:

SecurityAlert
| where TimeGenerated > ago(1h)
| where SystemAlertId == "<alert-id>"
| project TimeGenerated, AlertName, ProviderName, AlertSeverity

Use the following Advanced Hunting query instead:

AlertInfo
| where Timestamp > ago(1h)
| where AlertId == "<alert-id>"
| project Timestamp, AlertId, Title, ServiceSource, Severity

The following fields change:

Log Analytics fieldAdvanced Hunting field
TimeGeneratedTimestamp
SystemAlertIdAlertId
AlertNameTitle
ProviderNameServiceSource
AlertSeveritySeverity

Device process investigation

For example:

{
  "Query": "DeviceProcessEvents | where Timestamp > ago(24h) | where DeviceName == '<device-name>' | project Timestamp, DeviceName, FileName, ProcessCommandLine"
}

Email investigation

For example:

EmailEvents
| where Timestamp > ago(24h)
| where RecipientEmailAddress =~ "<[email protected]>"
| project Timestamp, NetworkMessageId, SenderFromAddress, RecipientEmailAddress, Subject, DeliveryAction

Handle empty results and errors

A successful Advanced Hunting query can return no rows. Check the number of results before running downstream actions:

length(body('Run_Hunting_Query')?['results'])

Continue only when the length is greater than 0. Otherwise, end the flow gracefully or handle the no-results condition explicitly.

Use the following guidance to troubleshoot common issues:

IssueLikely causeRecommended resolution
403 ForbiddenMissing Microsoft Graph permission or admin consentGrant ThreatHunting.Read.All and confirm admin consent.
401 UnauthorizedAuthentication configuration issueVerify the managed identity, audience, and Microsoft Graph authentication configuration.
Empty resultsTable, field, time range, or data availability mismatchValidate the query in Advanced Hunting and confirm that the expected data is available.
Expression failureThe playbook still expects Log Analytics row arraysUpdate expressions to use results and named JSON properties.
Query timeoutThe query is too broad or resource intensiveAdd time filters, project fewer columns, reduce joins, and limit results.
Field not foundThe Advanced Hunting schema differs from Log AnalyticsReview the Advanced Hunting schema and update the column names.

Optimize query performance and reliability

When you use Advanced Hunting queries in Logic App playbooks:

  • Include a time filter, such as Timestamp > ago(1h).
  • Apply filters as early as possible.
  • Use project to return only the columns required by the playbook.
  • Avoid broad search operations across large datasets.
  • Use take or limit when the playbook doesn't require all matching rows.
  • Test query runtime in Advanced Hunting before using the query in automation.
  • Handle authentication, authorization, throttling, timeout, and empty-result scenarios.

For example, prefer:

DeviceProcessEvents
| where Timestamp > ago(1h)
| where DeviceName == "device01.contoso.com"
| project Timestamp, DeviceName, FileName, ProcessCommandLine
| take 100

Avoid broad queries such as:

DeviceProcessEvents
| search "powershell"

Validate the updated playbook

Before you use the updated playbook in production, confirm that:

  • The Logic App no longer depends on the Log Analytics query action for the updated flow.
  • The playbook calls Microsoft Graph at /security/runHuntingQuery.
  • The Logic App identity has ThreatHunting.Read.All with admin consent.
  • The KQL query works as expected in Advanced Hunting.
  • Log Analytics tables and columns are mapped to the appropriate Advanced Hunting equivalents.
  • Response parsing uses results.
  • Downstream actions reference named properties instead of row indexes.
  • Empty-result handling is configured.
  • Error handling is configured for authentication, authorization, throttling, and timeout scenarios.
  • The playbook has been tested end to end with a controlled test case.

API limits and operational considerations

Microsoft Graph Advanced Hunting queries can return up to 100,000 rows per request. The optional Timespan parameter defaults to 30 days.

The API is also subject to tenant-level quotas and resource allocation. A 429 response indicates throttling or resource pressure. Retry the request later and review the response for more information.

Long-running requests can time out. Optimize the KQL query and narrow the time range when needed.

Explicitly define the time scope used by automation, either in KQL or through the request timespan. \ No newline at end of file