Update Logic App playbook automation

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 implementation Target implementation
Log Analytics or Azure Monitor Logs connector Microsoft Graph API call to Advanced Hunting
Workspace-based Microsoft Sentinel or Log Analytics tables Microsoft Defender XDR Advanced Hunting tables
Queries that use TimeGenerated Advanced Hunting queries that use Timestamp
Response parsing from the existing query action's output Response 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.

Requirement Details
Microsoft Defender XDR access Advanced Hunting data must be available in Microsoft Defender XDR.
Logic App identity Use a system-assigned managed identity, user-assigned managed identity, or application registration.
Microsoft Graph permission Grant ThreatHunting.Read.All. Admin consent is required.
Query validation access An administrator or analyst must be able to validate each query in Advanced Hunting in the Microsoft Defender portal.
Change control Test 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 type Permission Recommended use
Application ThreatHunting.Read.All Recommended for production Logic App automation.
Delegated ThreatHunting.Read.All Useful 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:

Setting Value
Authentication type Managed Identity
Identity System-assigned or user-assigned managed identity
Audience https://graph.microsoft.com
HTTP method POST
URI https://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.

Data Advanced Hunting table Notes
Defender XDR alert metadata AlertInfo Alert title, severity, category, service source, and alert ID
Alert entities or evidence AlertEvidence Related users, devices, files, URLs, IP addresses, and evidence
Device process activity DeviceProcessEvents Process creation and related endpoint process events
Device network activity DeviceNetworkEvents Inbound and outbound network connection events
Device file activity DeviceFileEvents File creation, modification, and file-system events
Device registry activity DeviceRegistryEvents Registry creation, modification, and deletion events
Device logon activity DeviceLogonEvents Device authentication and logon events
Email events EmailEvents Email delivery and message metadata
Email attachments EmailAttachmentInfo Attachment metadata for email messages
Email URLs EmailUrlInfo URLs observed in email messages
Post-delivery email actions EmailPostDeliveryEvents Post-delivery actions, such as zero-hour auto purge (ZAP)
Cloud app activity CloudAppEvents Cloud application and SaaS activity
Identity information IdentityInfo or IdentityAccountInfo Validate the table available in your tenant
Microsoft Entra ID sign-in events EntraIdSignInEvents or AADSignInEventsBeta Use 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 pattern Advanced 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 field Advanced Hunting field
TimeGenerated Timestamp
SystemAlertId AlertId
AlertName Title
ProviderName ServiceSource
AlertSeverity Severity

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 =~ "<user@contoso.com>"
| 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:

Issue Likely cause Recommended resolution
403 Forbidden Missing Microsoft Graph permission or admin consent Grant ThreatHunting.Read.All and confirm admin consent.
401 Unauthorized Authentication configuration issue Verify the managed identity, audience, and Microsoft Graph authentication configuration.
Empty results Table, field, time range, or data availability mismatch Validate the query in Advanced Hunting and confirm that the expected data is available.
Expression failure The playbook still expects Log Analytics row arrays Update expressions to use results and named JSON properties.
Query timeout The query is too broad or resource intensive Add time filters, project fewer columns, reduce joins, and limit results.
Field not found The Advanced Hunting schema differs from Log Analytics Review 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.