Get Started with the Slack API

In this lesson, we save the following codes so that we can access them throughout the course:

  1. Bot User OAuth Token: We use this to authenticate and specify the different scopes of the caller.
  2. Channel ID: We use this code to identify the Slack channel (group).
  3. 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:

  1. Go to Slack’s website to set up an account.
  2. Click “SIGN UP WITH EMAIL.”
  3. Enter your email and click “Continue.”
  4. Copy and paste the six-character code sent to your email.

Create a workspace

The user needs to sign up for Slack to use the API. It is advisable to make a new workspace for this course.

  1. Once we’ve signed up, click “Create a Workspace.”
  2. Enter the name of the company.
  3. Skip the option of inviting other people.
  4. Enter the channel’s name you want to start with.
  5. Launch your newly created workspace.

Create a Slack application

  1. Go to the Slack API link (log in to Slack before going to the API link).
  2. Click the “Create an app” button, which will show a pop-up.
  3. Click the “From scratch” button to configure the application’s scopes and settings.
  4. Add a name for your application and select the workspace you made.
  5. 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.

  1. Go to the “OAuth & Permissions” tab on the left-hand sidebar.
  2. Scroll down and click the “Add an OAuth Scope” button for the “Bot Token Scopes.”
  3. 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, and reactions:write.
  4. Scroll up and click the “Install to Workspace” button.
  5. Click “Allow” and copy the “Bot User OAuth Token.”
  6. 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.

  1. Go to your Slack application on your desktop or browser.
  2. Open the channel settings by clicking its name.
  3. Add the Slack application you made in the “Integrations” tab from the channel’s settings.
  4. Go back to the “About” tab and copy the ID beside the Channel ID.
  5. 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.

  1. Go to the Slack application on your desktop or browser.
  2. Click on your profile image in the top-right corner.
  3. Click the “Profile” button in the pop-up menu. You’ll see an expanded profile.
  4. Click the three dots labeled “More.”
  5. Click the “Copy Member ID” in the pop-up menu to copy the ID.
  6. 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 we added. Run the executable widget below to verify if all the keys entered are correct and work as they should.

Press + to interact
validation();

Once your setup is complete, you should see the following message on Slack in the channel where the application has been added: