Set Up the API keys
Follow the step-by-step instructions to configure Slack's API tokens.
In this lesson, we save the following codes so that we can access them throughout the course:
- Bot User OAuth Token: We use this to authenticate and specify the different scopes of the caller.
- Channel ID: We use this code to identify the channel (group) in Slack.
- Member ID: We use this code to identify a user or member.
Set up a Slack account
We’ll use the steps below to set up an account in Slack:
- Go to Slack’s website to set up an account.
- Click “SIGN UP WITH EMAIL.”
- Enter your email and click “Continue.”
- Copy and paste the 6-character code sent to your email.
Create a workspace
The user needs to sign up to Slack to use the API. It is advisable to make a new workspace for this course.
- Once we’ve signed up, click the “Create a Workspace” button.
- Enter the name of the company.
- Enter the channel’s name you want to start with.
- Skip the options of adding other people.
- Launch your newly created workspace.
Create a Slack application
- Go to the Slack API link (log in to Slack before going to the API link).
- Click the “Create an app” button, which will show a pop-up.
- Click the “From scratch” button to configure the application’s scopes and settings.
- Add the name for your application and select the workspace you made.
- Click the “Create App” button.
Add scopes and install the application
We’ll need an OAuth token provided by Slack to interact with its API. Go to the Slack API website and click on your application.
- Go to the “OAuth & Permissions” tab on the left-hand sidebar.
- Scroll down and click the “Add an OAuth Scope” button for the “Bot Token Scopes.”
- Add the following scopes:
chat:write
,channels:manage
,groups:write
,im:write
,mpim:write
,channels:join
,channels:history
,groups:history
,im:history
,mpim:history
,files:read
,files:write
,remote_files:read
,remote_files:share
,remote_files:write
,groups:read
,im:read
,mpim:read
,channels:read
,users:read
,users:write
,reactions:read
, andreactions:write
. - Scroll up and click the “Install to Workspace” button.
- Click “Allow” and copy the “Bot User OAuth Token”.
- Paste the token next to
TOKEN
in the code widget at the end of this lesson.
Add the Slack application to a channel
We’ll use the channel ID to interact with the API. For example, we’ll use it to send messages to the channel and more.
- Go to your Slack application on your desktop or browser.
- Open the channel settings by clicking its name.
- Add the Slack application you made in the “Integrations” tab from the channel’s settings.
- Go back to the “About” tab and copy the ID beside the Channel ID.
- Paste the ID in the code widget next to
CHANNEL_ID
at the end of this lesson.
Add your user ID
In certain API calls, we need to specify a user using their user ID. For this course, we’ll use your user ID.
- Go to the Slack application on your desktop or browser.
- Click on your profile image in the top-right corner.
- Click the “Profile” button in the pop-up menu. You’ll see an expanded profile.
- Click the three dots labeled “More.”
- Click “Copy Member ID” in the pop-up menu to copy the ID.
- Paste the ID in the code widget next to
USER_ID
at the end of this lesson.
Verification
Next, we need to verify the IDs and the API token that were added. Run the executable widget below to verify if all the keys entered are correct and work as they should.
Add the API keys below
# Using some hidden code to send a request to the# Slack API to verify that the setup is correct and complete!print(validation)
You should see the following message on Slack: