web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Using Post to a channe...
Power Automate
Unanswered

Using Post to a channel when a webhook request is received workflow for notifications to teams channel.

(4) ShareShare
ReportReport
Posted on by 7

We are migrating from O365 connectors to Workflows  - while testing posts to workflows from python script i am seeing this issue.

 

ExpressionEvaluationFailed. The execution of template action 'Send_each_adaptive_card' failed: the result of the evaluation of 'foreach' expression '@triggerOutputs()?['body']?['attachments']' is of type 'Null'. The result must be a valid array.

 

Please let me know how to fix this.

Categories:
I have the same question (0)
  • georgel Profile Picture
    8 on at

    I think that you will need to use the right format for adaptive card, such as the following in Python:

    json = {
     "type":"message",
     "attachments":[
     {
     "contentType":"application/vnd.microsoft.card.adaptive",
     "content":{
     "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
     "type":"AdaptiveCard",
     "version":"1.2",
     "body":[
     {
     "type":"TextBlock",
     "text":"Some error occurred",
     "color":"warning",
     "wrap":True
     }
     ]
     }
     }
     ]
    }
    
    requests.post(url, json=json, headers = {'Content-Type': 'application/json'})
  • Sayan Profile Picture
    818 Super User 2025 Season 2 on at

    Hii @Shankar18 

    The error message indicates that the attachments field in the webhook request's body is null or not an array, causing the foreach loop to fail.

     

    Solution:

    1. Ensure that the webhook request from the Python script includes the attachments field in the body.
    2. Verify the structure of the webhook request payload.
    3. Before the foreach loop, add a condition to check if attachments is not null and is an array.
    4. You can use a condition or initialize a variable with a default value if attachments is missing.

     

    ------------------------------------------------------------------------------------------------------------------------------

    If my suggestion helped you, please give it a Thumbs up 👍 and Mark it as a Solution 🎉 .
    Sayan Patra
    RPA Developer

  • minhhoangn Profile Picture
    40 on at

    Hello everybody,
    I am also having problems converting Office connector to Workflow,
    Currently I need to send messages via MS Teams using webhooks with commands
    // on Windows
    curl.exe -H "Content-Type:application/json" -d "{'text':'Hello World'}" <YOUR WEBHOOK URL>
    When I switched, I couldn't do this anymore.

    Workflow can only run step "When a Teams webhook request is received"

    In the return of the webhook url

    I have tried many card adapters searching on google but they don't work. My request is simply to send a plaintext message to the Teams channel. If possible, I would like to send an alert from Zabbix to the Teams channel. Previously, the webhook worked fine, but when I switched the workflow, I didn't know how to configure it

    Thank in advanced

    minhhoangn_1-1720574530759.png

    minhhoangn_0-1720574389158.png

  • minhhoangn Profile Picture
    40 on at

    It worked, here is my powershell script

    minhhoangn_0-1720575454729.png

    # Định nghĩa URL của HTTP POST
    $webhookUrl = "URL"
    # Định nghĩa nội dung của adaptive card
    $adaptiveCardPayload = @{
    type = "message"
    attachments = @(
    @{
    contentType = "application/vnd.microsoft.card.adaptive"
    content = @{
    "$schema" = "http://adaptivecards.io/schemas/adaptive-card.json"
    type = "AdaptiveCard"
    version = "1.2"
    body = @(
    @{
    type = "TextBlock"
    text = "Some error occurred"
    color = "warning"
    wrap = $true
    }
    )
    }
    }
    )
    } | ConvertTo-Json -Depth 10

    # Định nghĩa headers
    $headers = @{
    "Content-Type" = "application/json"
    }

    # Gửi yêu cầu HTTP POST
    Invoke-RestMethod -Uri $webhookUrl -Method POST -Body $adaptiveCardPayload -Headers $headers

     

    minhhoangn_1-1720575518172.png

     

     

  • brani145 Profile Picture
    5 on at

    Hi I am also having difficulty migrating O365 connectors to workflow. Previously I am using pymsteams library in python to send a message to my teams channel. It is HTML report. But I can't get the same result using workflows.

     

    For Example, my report looks like this with webhooks in the teams channel:

    brani145_0-1720652474696.png

    I am using this code in Python for current webhooks. 

    import pymsteams
    import sys


    mymessage = pymsteams.connectorcard("Webhook_URL")
    with open(sys.argv[1], 'r') as file:
    mymessage.text(file.read())
    mymessage.send()

     

    How can I achieve the same result using workflow? I have the workflow URL generated. Does the adaptive card have this capability?

     

    I took the reference from one of the above reply and used this code:

    import pymsteams
    import sys
    from bs4 import BeautifulSoup


    # Read the HTML file path from the command line
    html_file_path = sys.argv[1]

    # Read the HTML file
    with open(html_file_path, 'r') as file:
    html_content = file.read()

    # Use BeautifulSoup to strip HTML tags and get plain text
    soup = BeautifulSoup(html_content, 'html.parser')
    text_content = soup.get_text()

    # Create the adaptive card payload
    adaptive_card_payload = {
    "type": "message",
    "attachments": [
    {
    "contentType": "application/vnd.microsoft.card.adaptive",
    "content": {
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.2",
    "body": [
    {
    "type": "TextBlock",
    "text": text_content,
    "wrap": True
    }
    ]
    }
    }
    ]
    }

    # connector card object with workflow URL
    workflow_url = "https://prod2..."
    mymessage = pymsteams.connectorcard(workflow_url)

    # Add the adaptive card payload to the message
    mymessage.payload = adaptive_card_payload

    # Send the message
    mymessage.send()

     

    But it sends the file in plain text. How can I achieve the same results? Any help will be appreciated

  • minhhoangn Profile Picture
    40 on at

    yes, You probably just used an adaptercard like my comment.
    Sorry, I haven't found html support at the moment. I'm also having difficulty using Zabbix alerts via MS Teams workflow as it doesn't support html.
    Hope someone will help us.

  • Ryan_Tien Profile Picture
    12 on at

    Hi MinhHoangn , thanks for Your script ! , let ChatGPT help you make script Zabbix alerts via MS Teams, copy paste your script to chat GPT then type " translate this script powershell to script bash linux" 

  • minhhoangn Profile Picture
    40 on at

    Thank you, But It's not as simple as translating from powershell to shell. Because it is related to many other things.

  • Ryan_Tien Profile Picture
    12 on at
    #!/bin/bash
    webhookUrl="https://prod2-08.south.............."
    
    adaptiveCardPayload=$(cat <<EOF
    {
     "type": "message",
     "attachments": [
     {
     "contentType": "application/vnd.microsoft.card.adaptive",
     "content": {
     "\$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
     "type": "AdaptiveCard",
     "version": "1.2",
     "body": [
     {
     "type": "TextBlock",
     "text": "Test",
     "color": "warning",
     "wrap": true
     }
     ]
     }
     }
     ]
    }
    EOF
    )
    
    headers="Content-Type: application/json"
    
    # Send HTTP POST request
    curl -X POST -H "$headers" -d "$adaptiveCardPayload" "$webhookUrl"

    hi @minhhoangn , this script make by chatGPT when i give your script to it translate 😃, combine with link : https://www.youtube.com/watch?v=zZSXEvjpfbY you can make Zabbix alerts via MS Teams 

  • minhhoangn Profile Picture
    40 on at

    Perfect, Thank you so much. i can try do it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard