Skip to content

Integration Templates

Marcello Marchetti edited this page Jun 4, 2026 · 2 revisions

Agent Tasks — Integration Templates

Step-by-step guides for integrating XRCopilot Agent Tasks with Power Automate, SharePoint, and Azure Logic Apps.

Prerequisites: an Agent Task configured with a Webhook trigger, the generated API key, and the APIM subscription key. See Webhooks-Agent-Tasks for the full technical details. To invoke external HTTP endpoints from inside an orchestrator workflow, see Webhooks-Connections-Action-Steps.


Table of Contents


Required Credentials

All integrations require these credentials:

Credential Where to find it Where to configure it
APIM Subscription Key Provided by your XRCopilot administrator Ocp-Apim-Subscription-Key header
Webhook API Key Generated when the webhook is created (shown only once) X-Api-Key header
Hook ID Visible in the webhook configuration (format wh_...) URL path

Base URL:

https://apim-hipexr-prod-italynorth.azure-api.net/api/lab-public/hooks/{hookId}

Security: Store credentials in Azure Key Vault or in the environment variables of the flow/logic app. Do not embed them directly in the flow code.


Power Automate

Scenario 1: Manual trigger with email result delivery

A manually triggered flow that invokes an AI agent and sends the results via email.

When to use it: On-demand reports, ad hoc analysis, Q&A with the agent.

Step 1 — Create the flow

  1. Power Automate > My flows > New flow > Instant cloud flow
  2. Name: XRCopilot - Report On-Demand
  3. Trigger: Manually trigger a flow
  4. Add a text input to the trigger:
    • Input name: Question
    • Input type: Text

Step 2 — HTTP action (invoke webhook)

  1. Add an HTTP action
  2. Configuration:
Field Value
Method POST
URI https://apim-hipexr-prod-italynorth.azure-api.net/api/lab-public/hooks/wh_YOUR_HOOK_ID
Headers (see below)
Body (see below)

Headers:

Ocp-Apim-Subscription-Key: <YOUR_API_KEY>
X-Api-Key: <YOUR_WEBHOOK_API_KEY>
Content-Type: application/json

Body:

{
  "question": "@{triggerBody()['text']}",
  "requested_by": "@{triggerBody()['email']}",
  "date": "@{utcNow()}"
}

Step 3 — Verification condition

  1. Add a Condition action
  2. Condition: Status code is equal to 202
  3. If yes: continue
  4. If no: add a Send an email (V2) action with an error notification

Step 4 — Submission notification

  1. In the If yes branch, add Send an email (V2)
  2. Subject: [XRCopilot] Request submitted
  3. Body: Your request has been received. You will receive the results via email/XRCopilot inbox as soon as they are available.

Note: Results are delivered asynchronously via the output actions configured in the Agent Task (email, webhook, inbox). There is no need to wait inside the flow.


Scenario 2: Automatic trigger from a form and result reception

A flow that triggers when a user fills out a Microsoft Form and receives the results via a return webhook.

When to use it: Structured requests from internal users (e.g., analysis requests, document generation).

Step 1 — Create the form

  1. Microsoft Forms > New Form
  2. Suggested fields:
    • Request Type (Choice: Analysis, Report, Q&A)
    • Description (Long text)
    • Priority (Choice: High, Medium, Low)

Step 2 — Flow with Forms trigger

  1. Power Automate > New flow > Automated cloud flow
  2. Trigger: When a new response is submitted (Microsoft Forms)
  3. Action: Get response details

Step 3 — HTTP action

  1. Add an HTTP action with:

Body:

{
  "request_type": "@{outputs('Get_response_details')?['body/TipoRichiesta']}",
  "description": "@{outputs('Get_response_details')?['body/Descrizione']}",
  "priority": "@{outputs('Get_response_details')?['body/Priorita']}",
  "submitted_by": "@{outputs('Get_response_details')?['body/responder']}"
}

Headers: same as Scenario 1.

Step 4 — Result reception (optional)

To receive results in the flow, configure a second flow with a When an HTTP request is received trigger. See the Receiving Results section.


Scenario 3: Scheduled daily trigger

A flow that invokes the agent every day at a preset time.

When to use it: Automatic daily reports, monitoring, digests.

Note: This scenario is an alternative to XRCopilot's native schedule. Use the native schedule when no additional logic is needed in the flow.

Step 1 — Create the flow

  1. Power Automate > New flow > Scheduled cloud flow
  2. Frequency: Day, time: 09:00, timezone: (UTC+01:00) Rome

Step 2 — HTTP action

Body:

{
  "report_date": "@{formatDateTime(utcNow(), 'yyyy-MM-dd')}",
  "report_type": "daily_summary"
}

Headers: same as Scenario 1.


SharePoint

Scenario 1: Document analysis on upload

When a document is uploaded to a SharePoint document library, the flow invokes the agent to analyze it.

When to use it: Automatic document classification, data extraction, compliance checks.

Step 1 — Create the flow

  1. Power Automate > New flow > Automated cloud flow
  2. Trigger: When a file is created (properties only) (SharePoint)
  3. Configure:
    • Site Address: the SharePoint site
    • Library Name: the target document library

Step 2 — Get the file link

  1. Add a Get file properties action (SharePoint)
  2. Add a Create sharing link for a file or folder action (SharePoint)
    • Link Type: Organization (internal link)
    • Link Scope: Organization

Step 3 — HTTP action

Body:

{
  "action": "analyze_document",
  "file_name": "@{triggerOutputs()?['body/{FilenameWithExtension}']}",
  "file_url": "@{outputs('Create_sharing_link')?['body/link/webUrl']}",
  "library": "@{triggerOutputs()?['body/{Path}']}",
  "uploaded_by": "@{triggerOutputs()?['body/Author/Email']}"
}

Step 4 — Update SharePoint metadata (optional)

If you configure an outbound webhook to receive the results, a second flow can update the SharePoint file metadata with the analysis results:

  1. Flow with a When an HTTP request is received trigger
  2. Action: Update file properties (SharePoint)
    • Update custom columns (e.g., Classification, Summary)

Scenario 2: SharePoint list processing

Process SharePoint list items in batch, sending them to the agent for analysis or enrichment.

When to use it: Data enrichment, batch analysis, content generation for each item.

Step 1 — Create the flow

  1. Trigger: Recurrence (e.g., every Monday at 8:00)
  2. Action: Get items (SharePoint)
    • Filter: Status eq 'Da elaborare'

Step 2 — Apply to each

  1. Add Apply to each over the item collection
  2. Inside the loop, add an HTTP action

Body:

{
  "item_id": "@{items('Apply_to_each')?['ID']}",
  "title": "@{items('Apply_to_each')?['Title']}",
  "description": "@{items('Apply_to_each')?['Description']}",
  "action": "enrich"
}
  1. After the HTTP action, add Update item to change the status to In elaborazione

Caution: Respect the rate limit. If the list has many items, use batchWindowSeconds > 0 in the webhook configuration to aggregate the requests.


Azure Logic Apps

Scenario 1: Orchestration with Service Bus

Integrate XRCopilot into a larger workflow that uses Azure Service Bus to decouple the steps.

When to use it: Enterprise pipelines, multi-system orchestrations, workflows with compensation.

Step 1 — Create the Logic App

  1. Azure Portal > Logic Apps > Create > Consumption (or Standard)
  2. Workflow: Blank Logic App

Step 2 — Service Bus trigger

  1. Trigger: When a message is received in a queue (auto-complete)
  2. Queue: agent-task-requests (or your queue name)

Step 3 — Parse the message

  1. Action: Parse JSON
  2. Schema:
{
  "type": "object",
  "properties": {
    "correlationId": { "type": "string" },
    "requestType": { "type": "string" },
    "payload": { "type": "object" }
  }
}

Step 4 — HTTP action

  1. Action: HTTP

URI: https://apim-hipexr-prod-italynorth.azure-api.net/api/lab-public/hooks/wh_YOUR_HOOK_ID

Headers:

Ocp-Apim-Subscription-Key: @{parameters('ApimKey')}
X-Api-Key: @{parameters('WebhookApiKey')}
Content-Type: application/json

Body:

Note: @{...} expressions are evaluated by Logic Apps at runtime; the resulting body is valid JSON.

{
  "correlation_id": "@{body('Parse_JSON')?['correlationId']}",
  "request_type": "@{body('Parse_JSON')?['requestType']}",
  "data": @{body('Parse_JSON')?['payload']}
}

Step 5 — Error handling

  1. Configure Run after on the HTTP action: has failed, has timed out
  2. In the error branch: send a message to the dead letter queue or notify via email

Best practice: Use the Logic App parameters (or Key Vault references) for credentials, not inline values.

Step 6 — Logic App parameters

Configure the parameters in the designer or in the ARM template:

Parameter Type Value
ApimKey SecureString The APIM subscription key
WebhookApiKey SecureString The webhook API key

Scenario 2: Incoming email processing

When an email with specific characteristics arrives, extract the content and invoke the agent with it.

When to use it: Customer support automation, email request analysis, automatic triage.

Step 1 — Email trigger

  1. Trigger: When a new email arrives (V3) (Office 365 Outlook)
  2. Filters:
    • Subject Filter: [Support]
    • Include Attachments: Yes (if needed)

Step 2 — HTTP action

Body:

Note: @{...} expressions are evaluated by Logic Apps at runtime; the resulting body is valid JSON.

{
  "action": "analyze_email",
  "subject": "@{triggerOutputs()?['body/subject']}",
  "body": "@{triggerOutputs()?['body/bodyPreview']}",
  "sender": "@{triggerOutputs()?['body/from']}",
  "received_at": "@{triggerOutputs()?['body/receivedDateTime']}",
  "has_attachments": @{triggerOutputs()?['body/hasAttachments']}
}

Step 3 — Attachment handling (optional)

If the email has attachments:

  1. Apply to each over the attachments
  2. Create file (OneDrive/SharePoint) to save the attachment
  3. Include the link in the webhook payload

Receiving Results (Outbound Webhook)

To receive execution results in the flow/logic app, configure an HTTP endpoint as an output action in the Agent Task.

Power Automate

Step 1 — Create the receiving flow

  1. Power Automate > New flow > Automated cloud flow
  2. Trigger: When an HTTP request is received
  3. Request Body JSON Schema:
{
  "type": "object",
  "properties": {
    "executionId": { "type": "string" },
    "taskId": { "type": "string" },
    "taskName": { "type": "string" },
    "companyId": { "type": "string" },
    "status": { "type": "string" },
    "durationMs": { "type": "integer" },
    "timestamp": { "type": "string" },
    "agentResponse": { "type": "string" },
    "files": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "fileName": { "type": "string" },
          "url": { "type": "string" },
          "contentType": { "type": "string" }
        }
      }
    }
  }
}

Note: as of May 22, 2026, the outbound webhook body is templated. The schema shown above is the default — it is emitted when bodyTemplate is not configured on the XRCopilot side. If the template is customized, the schema changes accordingly. See the "Custom body templates" section in Webhooks-Agent-Tasks.

  1. Copy the HTTP POST URL generated by the trigger

Step 2 — Configure the output action in XRCopilot

  1. In the Agent Task editor > Output tab
  2. Enable Outbound Webhook
  3. Paste the Power Automate trigger URL
  4. Method: POST
  5. Include Full Response: enabled

Step 3 — Process the results

In the receiving flow, after the trigger:

  1. Condition: status is equal to Completed
  2. If yes:
    • Save agentResponse to SharePoint/OneDrive
    • Send an email with the results
    • Update a CRM record
  3. If no:
    • Notify the error via Teams/email
  4. Response: return 200 OK with body { "received": true }

Azure Logic Apps

Identical to the Power Automate pattern. Use the When an HTTP request is received trigger and configure the JSON schema as above.


Troubleshooting

Common errors

Problem Cause Solution
HTTP 401 Unauthorized Missing/incorrect API key or APIM key Check both headers. The webhook API key is case-sensitive.
HTTP 403 Forbidden Webhook disabled or IP not in whitelist Verify that the webhook is enabled and that the connector's IP is in the whitelist.
HTTP 404 Not Found Incorrect Hook ID Check the hookId in the URL (format wh_...).
No results received Output action not configured Verify that at least one output action (email/webhook/inbox) is enabled in the Output tab.
Duplicate results Receiving flow without deduplication Use the X-XRCopilot-ExecutionId header (or X-Idempotency-Key) for deduplication.
Flow timeout Execution timeout too low Increase timeoutSeconds in the Agent Task's Policy tab.
Quota exceeded Too many daily executions Increase maxDailyExecutions in the Policy tab, or use batching.

XRCopilot outbound webhook IPs

To configure your receiving endpoint's firewall or access rules, outbound webhooks originate from the platform's outbound IPs (Italy North region). Contact your XRCopilot administrator for the up-to-date list of outbound IPs.

Logs and diagnostics

  1. Monitoring tab of the Agent Task: execution statistics, trend charts, quota usage
  2. Execution Logs: detail of each execution (input, output, duration, errors)
  3. Delivery Logs: delivery status for each output action (delivered/failed/retrying)

See Also

Clone this wiki locally