Get the Slack API Credentials (Webhooks)

This post is part of the complete guide on Slack API with Python

To post to Slack API with Python you will need to create a Slack API app and get the Webhook URL. In this step-by-step guide, we will see how to get the webhook necessary to use the Slack API.

  1. Create Slack App
  2. Add the Incoming Webhooks
  3. Activate the Webhooks
  4. Add the Webhooks to the workspace
  5. Give access to your Workspace
  6. Add the Webhook URL into a credentials files

Create Your Slack App

Go to Slack App and click on “Create App”

Add the Incoming Webhooks

Webhooks are the simplest way to post messages from Python to Slack.


Subscribe to my Newsletter


In your app features, go to Incoming Webhooks.

Activate the Webhook

Add Your Webhook to Your Slack Workspace

Now it is time to add the Webhook to your Slack Workspace.

Some organisations will go through a validation process, but you could use your personal Slack profile to make the process easier if your organisation isn’t responding to your request.

Click on “Add New Webhook to Workspace”.

Allow The Access to the Workspace

Now it is time to approve the access to your Slack Webhook.

Here, I decided to send the alerts to myself.

Copy the Webhook URL

The next step is to copy the Slack Webhook URL into a credentials.json file.

It is good practice not to add the credentials into your code. By adding it to a JSON file, it allows you to add that file to Gitignore, so it is never committed to Github.

The structure of the credentials files goes like this:

{
    "slack_webhook":"https://hooks.slack.com/services/XXXXXXXX"
}

This is it. We have seen how to get the Webhook URL to the Slack API. In the next posts, we will see how to send a message to the Slack API using Python and make an automated robots.txt checker.

5/5 - (1 vote)