Back

Complete Guide to Building a Slack API Integration

Apr 4, 202425 minute read

Overview

Slack is a cloud-based team collaboration and communication platform that enables users to send messages, share files, and integrate with various tools and services, all within a single workspace. As of January 2023, Slack reported having over 18 million daily active users.

What can you do with the Slack API?

The Slack API allows interaction with various data models, each serving different purposes within the Slack ecosystem. Here's a breakdown of the data models you can interact with and what is possible for each:

  • Block Kit Data Model Objects: These are used for constructing Slack-specific data structures. They include basic objects like BaseObject, EnumValidator, JsonObject, and JsonValidator. These objects are essential for creating and manipulating blocks, which are the building blocks of messages, modals, and app surfaces in Slack. You can use these objects to create complex and interactive messages, modals, and other UI components within Slack.

  • Datastores: Datastores are a Slack-hosted way to store data for your workflow apps. They are backed by DynamoDB and use three basic types of data units: tables, items, and attributes. Tables are collections of items, and items are collections of attributes. You can define your own datastores to store and manage data specific to your app's functionality. This includes storing user drafts, messages, and other relevant information. Datastores are available for workflow apps only and require a paid plan.

  • Modals: Modals are the Slack app equivalent of an alert box, pop-up, or dialog box. They are used to capture and maintain focus within Slack until the user submits or dismisses the modal. This makes them a powerful tool for engaging with users. Modals can be used with other app surfaces such as messages and Home tabs. You can compose view layouts and add interactivity to views using Block Kit. A modal can hold up to 3 views at a time in a view stack, allowing for a dynamic and interactive user experience.

  • Conversations API: The Conversations API provides a unified interface to work with all the channel-like things encountered in Slack, including public channels, private channels, direct messages, group direct messages, and shared channels. You can use this API to review history, create or archive channels, invite team members, set conversation topics and purpose, and more. The types of channels you interface with in the Conversations API are governed by corresponding permission scopes, such as channels:read for public channels and groups:read for private channels.

Each of these data models and APIs offers a range of functionalities that can be leveraged to build powerful and interactive Slack apps and workflows.

Potential use cases

Here is the markdown text with the trailing list of URLs and citation references removed, and any URLs inside the content formatted correctly:

Based on the information provided in the sources, here are five potential use cases that can be enabled using the Slack API:

  • Automated Onboarding and Provisioning: Use the Slack API to create custom bots that guide new employees through the onboarding process, provisioning necessary tools and resources, and ensuring they have access to all relevant information and channels.

  • Approval Workflows: Develop integrations that streamline approval processes within the organization. For example, automating the approval of expense reports or time-off requests directly within Slack can save time and reduce manual workload.

  • Visibility and Alerts: Utilize the Slack API to create alerts for specific events or data changes in other systems. This could include sending notifications to a Slack channel when a new lead is submitted on a marketing site or when a critical system alert is triggered.

  • Enhanced Collaboration and Communication: Leverage the Slack API to build bots that facilitate better communication and collaboration within the team. For instance, a bot could summarize daily stand-ups, remind team members of upcoming deadlines, or even provide insights from external data sources to inform discussions.

  • Integration with External Tools: Use the Slack API to create custom integrations with external tools and services. This could range from CRM systems like Salesforce or HubSpot, where updates or actions in these tools can trigger notifications or messages in Slack, enhancing team collaboration and awareness.

Building with Slack's API

How to get a Slack developer account and API Keys?

To get a developer account for Slack and create an API integration, follow these steps:

  1. Join the Slack Developer Program: First, you need to register for the Slack Developer Program. You can register on the Slack Developer Program page.

  2. Create a Slack App: Once you have a developer account, you can create a Slack app. To create an app, navigate to the Slack API website and use the "Create app" button. You'll need to select the workspace you'd like the app to be in from the dropdown menu in the top right corner, then click "Build".

  3. Obtain an API Token: After creating your app, you'll need to obtain an API token. This token is crucial for your app to interact with the Slack API. You can follow the tutorial on how to quickly get and use a Slack API token to understand the process of creating and using a token.

  4. Use the API Token: With your API token, you can start interacting with the Slack API. You can use the Web API's method tester to test any public Web API method with your token and evaluate the response. This allows you to perform actions around a Slack workspace on your application's behalf, such as listing public channels in a workspace.

Remember, the API token you obtain is powerful and should be kept secure. It's equivalent to a classic legacy tester token but operates as a bot instead of a user. Be mindful of the permissions you request for your token to ensure it only has access to the necessary scopes for your app's functionality.

https://api.slack.com/web

Open API Spec

https://github.com/slackapi/slack-api-specs

API Explorer

Run Queries against the Slack API

Slack SDKs

TypeScript Logo

Typecript / Javascript

Top Slack SDK on NOM

Ruby Logo

Ruby

Top Slack SDK on Rubygems

Python Logo

Python

Top Slack SDK on PyPi

PHP Logo

PHP

Top Slack SDK on Packagist

C Sharp Logo

C#

Top Slack SDK on NuGet

Slack API Details

What type of API does Slack provide?

Slack's API is not a REST API but rather a collection of HTTP RPC-style methods. These methods are designed to be used over HTTP, with URLs structured as https://slack.com/api/METHOD_FAMILY.method. While it shares foundations with REST in terms of using HTTP, it does not strictly adhere to the REST architectural style.

In summary, Slack's API is HTTP-based and uses RPC-style methods, which is different from the REST, GraphQL, or SOAP API styles.

Does the Slack API have webhooks?

Yes, the official Slack API includes webhooks, specifically through the use of incoming webhooks. Incoming webhooks allow you to post messages from apps into Slack. To use incoming webhooks, you need to create a Slack app, enable incoming webhooks, create an incoming webhook, and then use the generated webhook URL to post messages to Slack. These messages can include text and various formatting options, making them highly customizable. However, it's important to keep the webhook URL secret and safe, as it contains a secret that should not be shared publicly.

In addition to incoming webhooks, the Slack API also offers the Events API, which is a more comprehensive way to build apps and bots that respond to activities in Slack. With the Events API, you can subscribe to various event types related to channels, direct messages, and more. The event types you can subscribe to are directly tied to the OAuth permission scopes awarded as users install your Slack app. This means you can choose to subscribe to specific event types that are relevant to your app's functionality, without worrying about the ones you don't need. The Events API also supports using Socket Mode to receive events through a dynamic WebSocket, offering an alternative to the traditional public HTTP endpoint method.

To subscribe to event types using the Events API, you need to create a Slack app, enable Event Subscriptions in your app settings, and then select the event types you want to subscribe to. The permission model for the Events API leverages Slack's existing OAuth scope system, allowing you to control access to events based on the scopes your app has been granted. For example, if your app has access to files through the files:read scope, you can subscribe to file-related events such as file_created and file_deleted.

In summary, the Slack API offers both incoming webhooks for simple message posting and the Events API for more complex interactions and event subscriptions. Each method serves different purposes, with incoming webhooks being suitable for straightforward message posting and the Events API offering a broader range of functionalities for building interactive Slack apps and bots.

Rate Limits and other limitations

The Slack API employs rate limits to ensure a predictable and pleasant experience for users. These limits vary depending on the specific feature or API method being used. Here's a summary of the key rate limits:

  • Web API Rate Limits: The Web API rate limits are evaluated per method, per workspace, with rate limit windows per minute. Each method is assigned one of four rate limit tiers (Tier 1 to Tier 4), with Tier 1 accepting the fewest requests and Tier 4 the most. There's also a special tier for unique rate-limiting behavior per method. The rate limits for each tier are as follows:

  • Tier 1: 1+ requests per minute, with a small amount of burst behavior tolerated.

  • Tier 2: 20+ requests per minute, allowing for occasional bursts.

  • Tier 3: 50+ requests per minute, suitable for methods with paginating collections of conversations or users, and sporadic bursts are welcome.

  • Tier 4: 100+ requests per minute, offering a large request quota and generous burst behavior.

  • Special Tier: Varies, with unique rate limiting conditions. For example, chat.postMessage generally allows posting one message per second per channel, while also maintaining a workspace-wide limit.

  • Posting Messages: Apps may post no more than one message per second per channel, with short bursts allowed. If bursts exceed available limits, users may see an error message indicating that some messages from your app are not being displayed.

  • Incoming Webhooks: Similar to posting messages, there's a limit of 1 message per second per channel, with short bursts allowed.

  • Events API: Event deliveries to your server via the Events API are rate-limited to 30,000 deliveries per workspace per hour. When a workspace generates more than 30,000 events, you'll receive an app_rate_limited event.

  • Workflow Triggers: For event triggers, the limit is 10,000 per hour, and for webhook triggers, it's 10 per minute.

  • Responding to Rate Limits: If you exceed a rate limit, Slack will return an HTTP 429 Too Many Requests error, and a Retry-After HTTP header containing the number of seconds until you can retry. It's recommended to design your apps with a limit of 1 request per second for any given API call, knowing that temporary bursts are allowed.

  • Burst Limiting: While rate limits define the maximum requests allowed in a specific timeframe, burst limits define the maximum rate of requests allowed concurrently. Slack does not share precise burst limits externally but recommends designing apps with a limit of 1 request per second, allowing for temporary bursts.

  • Other Functionality: Slack reserves the right to rate limit other functionality to prevent abuse, spam, denial-of-service attacks, or other security issues. Where possible, descriptive error messages are returned.

It's important to handle rate limits in your application to ensure a good user experience. This involves limiting the number of API calls your app makes, caching data that doesn't change often, and implementing logic to handle rate limiting errors, such as waiting for the specified Retry-After time before retrying a request.

Latest API Version

The most recent version of the Slack API, as of April 2024, is 2.21.0.

Status Page

The most current status page URL for Slack is not directly provided in the search results. However, based on the information available, Slack's status page can be accessed through their official website or by searching for "Slack Status" in a web browser. The status page typically provides information on the current operational status of Slack's services, including any ongoing incidents or maintenance activities. For the most accurate and up-to-date information, it's recommended to visit the official Slack status page directly.

Code Examples

Building authentication

Here are the steps to set up authentication for the Slack API:

  1. Obtain the necessary OAuth client ID and client secret from your Slack app settings.

  2. Construct the authorization URL with the required parameters:

    GET https://slack.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&response_type=code&scope=REQUIRED_SCOPES
    

    Replace YOUR_CLIENT_ID, YOUR_REDIRECT_URI, and REQUIRED_SCOPES with your actual values. The REQUIRED_SCOPES should be a space-separated list of the necessary scopes for your application.

  3. Redirect the user to the authorization URL. The user will be prompted to sign in to Slack and grant permissions to your application.

  4. After the user grants permission, Slack will redirect back to your specified redirect_uri with a code parameter in the query string.

  5. Exchange the authorization code for an access token by making a POST request to the OAuth access endpoint:

    POST https://slack.com/api/oauth.access
    Content-Type: application/x-www-form-urlencoded
    
    client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&code=AUTHORIZATION_CODE&redirect_uri=YOUR_REDIRECT_URI
    

    Replace YOUR_CLIENT_ID, YOUR_CLIENT_SECRET, AUTHORIZATION_CODE, and YOUR_REDIRECT_URI with your actual values.

  6. Slack will respond with a JSON object containing the access token and other relevant information. Extract the access token from the response.

  7. Store the access token securely for future API requests. The access token will be used to authenticate your application when making API calls to Slack.

  8. Use the access token in the Authorization header of your API requests. For example:

    curl -H "Authorization: Bearer ACCESS_TOKEN" https://slack.com/api/METHOD
    

    Replace ACCESS_TOKEN with your actual access token and METHOD with the desired Slack API method.

By following these steps, you should be able to set up authentication for the Slack API and start making authenticated requests to interact with Slack's functionality.