How to send Message from Ignition to MS Teams via Workflows

Hello everyone,:grinning_face:

I'm trying to send an alert from Ignition 8.1 to a Microsoft Teams chat. To do this, I'm using a Teams workflow(send webhook alerts to the chat) to get the webhook URL.

I've already successfully tested the webhook URL and the JSON payload using Postman, which works perfectly. This tells me the workflow itself is set up correctly.

However, when I run the script in the Ignition Script Console, nothing happens. There's no error message, and the HTTP Status Code output is completely blank. This suggests a network issue, but I'm looking for any specific settings or common pitfalls I might be missing on the Ignition Gateway side. Here is the script I'm using:

import json
import urllib2
webhook_url = "https://prod-145.westus.logic.azure.com:XXXX.XXXX"
payload = { "text": "Test" }
try:
    response= system.net.httpPost( 
        url=webhook_url,    
        contentType="application/json",
        data=json.dumps(payload),
        timeout=10
        )
print "HTTP Status Code:", response
except Exception as e:
    print "Connection failed!"
    print "error message:", str(e)

The output I get is: HTTP Status Code: (blank)

Any advice is greatly appreciated!

Not sure why you are importing these?

Why aren't you using system.util.jsonEncode()

Can you post screenshots of your postman config?

3 Likes

Also, you should probably be using system.net.httpClient()

2 Likes

Thank you , I solved the problem by using client = system.net.httpClient()

Be sure to follow the recommended reuse pattern for system.net.httpClient or your applicaton will suffer. (More of a requirement than a recommendation when you get past just testing.)

3 Likes