Skip to content

Instantly share code, notes, and snippets.

@DanEdens
Forked from devStepsize/slack_webhook_post.py
Last active January 15, 2020 17:33
Show Gist options
  • Save DanEdens/100d10535ba9bce06a6912f858d55380 to your computer and use it in GitHub Desktop.
Save DanEdens/100d10535ba9bce06a6912f858d55380 to your computer and use it in GitHub Desktop.
POST a JSON payload to a Team's channel Incoming Webhook using Python requests
'''
This is an example of how to send data to Team's webhooks in Python with the
requests module.
Documentation for Team's Incoming Webhooks:
https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/what-are-webhooks-and-connectors
Card playground:
https://messagecardplayground.azurewebsites.net/
'''
import json
import requests
import os
# Set the webhook_url to the one provided by creating a webhook connector.
webhook_url = 'https://outlook.office.com/webhook/*************************/IncomingWebhook/*************************'
Watchdog_data = os.environ['sitecheckdata'] #path to card's json file. use "set sitecheckdata '%userprofile%/desktop/path/to/file'"
response = requests.post(
webhook_url, data=json.dumps(Watchdog_data),
headers={'Content-Type': 'application/json'}
)
if response.status_code != 200:
raise ValueError(
'Request to Teams returned an error %s, the response is:\n%s'
% (response.status_code, response.text)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment