POST a JSON payload to a Slack Incoming Webhook using Python requests
✓ Published0🌍 Public
Aalvinthai
Last edited Apr 21, 2016
Created on Oct 12, 2018
This example demonstrates sending a JSON payload to a Slack Incoming Webhook using the Python `requests` module. The code constructs a `slack_data` dictionary containing the message text, then posts it to the webhook URL with `requests.post`, setting the `Content-Type` header to `application/json`. It checks the response status code and raises a `ValueError` if the request fails, including the error code and response body in the exception. The webhook URL is a placeholder from Slack’s service, and the data source is the hardcoded message string.
AI-generated description