{"id":210,"date":"2018-09-04T14:37:48","date_gmt":"2018-09-04T13:37:48","guid":{"rendered":"http:\/\/brgeek.com.br\/wordpress\/?p=210"},"modified":"2018-09-04T14:37:48","modified_gmt":"2018-09-04T13:37:48","slug":"slack-webhooks-json-python","status":"publish","type":"post","link":"http:\/\/brgeek.com.br\/wordpress\/2018\/09\/04\/slack-webhooks-json-python\/","title":{"rendered":"Slack Webhooks &#8211; Json &#8211; Python"},"content":{"rendered":"<p>Hello, there fellow friends!<br \/>\nThis is an example of how to send data to Slack webhooks in Python with the requests module.<br \/>\nFirst, you need to set up your incoming-webhook into your desired slack channel and use the example below to test your payload.<br \/>\nDon&#8217;t forget to change the code webhook_url<\/p>\n<p><code class=\"\" data-line=\"\"><br \/>\n&#039;&#039;&#039;<br \/>\nThis is an example of how to send data to Slack webhooks in Python with the<br \/>\nrequests module.<br \/>\nDetailed documentation of Slack Incoming Webhooks:<br \/>\nhttps:\/\/api.slack.com\/incoming-webhooks<br \/>\n&#039;&#039;&#039;<\/p>\n<p>import json<br \/>\nimport requests<\/p>\n<p># Set the webhook_url to the one provided by Slack when you create the webhook at https:\/\/my.slack.com\/services\/new\/incoming-webhook\/<br \/>\nwebhook_url = &#039;https:\/\/hooks.slack.com\/services\/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&#039;<br \/>\nslack_data = {&#039;text&#039;: &quot;API call using Python test by Michael &quot;}<\/p>\n<p>response = requests.post(<br \/>\n    webhook_url, data=json.dumps(slack_data),<br \/>\n    headers={&#039;Content-Type&#039;: &#039;application\/json&#039;}<br \/>\n)<br \/>\nif response.status_code != 200:<br \/>\n    raise ValueError(<br \/>\n        &#039;Request to slack returned an error %s, the response is:\\n%s&#039;<br \/>\n        % (response.status_code, response.text)<br \/>\n    )<\/p>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, there fellow friends! This is an example of how to send data to Slack webhooks in Python with the requests module. First, you need to set up your incoming-webhook into your desired slack channel and use the example below to test your payload. Don&#8217;t forget to change the code [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":211,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[28,8,29,6,26,27],"class_list":["post-210","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-json","tag-michael-goulart","tag-payload","tag-powershell","tag-slack","tag-webhook"],"jetpack_featured_media_url":"http:\/\/brgeek.com.br\/wordpress\/wp-content\/uploads\/2018\/09\/json-1.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":1,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":212,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/210\/revisions\/212"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/media\/211"}],"wp:attachment":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}