Get Channel Properties
Learn to use Slack API calls to get various data from channels and the workspace.
In this lesson, we retrieve information from Slack’s Conversations API. This set of endpoints is useful when we create an application for different workspaces.
Let’s look at the following endpoints in this lesson:
conversations.history
: This endpoint fetches a channel’s history, including messages and events.conversations.info
: This endpoint retrieves information about a channel.conversations.list
: This endpoint lists all channels in a Slack team.conversations.members
: This endpoint retrieves members of a channel.conversations.replies
: This endpoint retrieves a thread of messages posted to a channel or chat.
Get message history
To acquire the message history, we access the https://slack.com/api/conversations.history
endpoint. This endpoint allows us to get all the messages that have been sent in a channel. You’re advised to use the limit
parameter so that the response is not too large.
Request parameters
Some important query parameters for the conversations.history
endpoint are as follows:
Parameter | Type | Category | Description |
| token | required | Authentication tokens carry the required scopes that govern the usage of different Slack applications and APIs. We usually pass these tokens as an HTTP Authorization header or as a POST parameter. |
| string | required | This parameter specifies the channel to which the message will be posted. It can be a public channel, a private group, or an IM channel (direct message). The value for this parameter can either be an encoded ID or a name of a channel. |
| string | optional | This parameter is a string of characters used to "point" to the next "page" of data. We paginate through collections of data by setting the |
| boolean | optional | This parameter includes messages with the |
| string | optional | This is the latest timestamp. All messages before this timestamp will be included in the results. Its default is the current time. |
| number | optional | This is the maximum number of items to return. Items fewer than the requested number may be returned. |
| string | optional | This is the oldest timestamp. All messages after this timestamp will be included in the results. |
Let’s call the conversations.history
endpoint. Click the “Run” button to get a paginated response of messages of the specified channel.
import fetch from "node-fetch";const url = new URL("https://slack.com/api/conversations.history");const headerParameters = {Authorization: "Bearer {{TOKEN}}","Content-Type": "application/json; charset=UTF-8",};const queryParameters = new URLSearchParams({channel: "{{CHANNEL_ID}}",limit: 2,});const options = {method: "GET",headers: headerParameters,};async function getHistory() {try {url.search = queryParameters;const response = await fetch(url, options);printResponse(response);} catch (error) {printError(error);}}getHistory();
Let’s look at the highlighted lines in the code widget shown above:
- Lines 10–13: We specify the channel ID and
limit
parameters. - Lines 22–23: We provide the query parameters and call the
conversations.history
endpoint that is specified in line 3.
Response fields
The response contains a messages
field containing a list of all messages sent to the channel and a cursor value for pagination.
Note: Visit this lesson to view the details of the elements in the
messages
list.
Get the channel info
To get the channel info, we access the https://slack.com/api/conversations.info
endpoint. We can access information like the creator
, the purpose
, or the topic
parameters with this endpoint.
Request parameters
Some important query parameters for the conversations.info
endpoint are as follows:
Parameter | Type | Category | Description |
| token | required | Authentication tokens carry the required scopes that govern the usage of different Slack applications and APIs. We usually pass these tokens as an HTTP Authorization header or as a POST parameter. |
| string | required | This parameter specifies the channel to which the message will be posted. It can be a public channel, a private group, or an IM channel (direct message). The value for this parameter can either be an encoded ID or a name of a channel. |
| boolean | optional | Set this to |
| boolean | optional | Set to |
Let’s call the conversations.info
endpoint. Click the “Run” button to get information about a channel.
import fetch from "node-fetch";const url = new URL("https://slack.com/api/conversations.info");const headerParameters = {Authorization: "Bearer {{TOKEN}}","Content-Type": "application/json; charset=UTF-8",};const queryParameters = new URLSearchParams({channel: "{{CHANNEL_ID}}",});const options = {method: "GET",headers: headerParameters,};async function getChannelInfo() {try {url.search = queryParameters;const response = await fetch(url, options);printResponse(response);} catch (error) {printError(error);}}getChannelInfo();
Let’s look at the highlighted lines in the code widget shown above:
- Line 11: We specify the channel to get its info.
- Lines 21–22: We provide the query parameters and call the
conversations.info
endpoint specified in line 3.
Response fields
Apart from the ok
property, the response includes the channel info in the channel
property.
Note: Visit this lesson to view the details of the
channel
object.
Get the list of all channels
To get the list of all channels, we access the https://slack.com/api/conversations.list
endpoint. This endpoint returns all the channels in a workspace.
Note: This endpoint uses pagination. Pass the
next_cursor
as the cursor in the next call to continue getting the list of conversations in a workspace.
Request parameters
Some important query parameters for the conversations.list
endpoint are as follows:
Parameter | Type | Category | Description |
| token | required | Authentication tokens carry the required scopes that govern the usage of different Slack applications and APIs. We usually pass these tokens as an HTTP Authorization header or as a POST parameter. |
| string | optional | This parameter is a string of characters used to "point" to the next "page" of data. We paginate through collections of data by setting the |
| boolean | optional | We set this to |
| number | optional | This is the maximum number of items to return. Items fewer than the requested number may be returned. |
| string | optional | This is the encoded team ID to list channels in. It is required if the token belongs to an org-wide application. |
| string | optional | This parameter is used to mix and match channel types by providing a comma-separated list of any combination of |
Let’s call the conversations.list
endpoint. Click the “Run” to get the list of conversations taking place in the workspace.
import fetch from "node-fetch";const url = new URL("https://slack.com/api/conversations.list");const headerParameters = {Authorization: "Bearer {{TOKEN}}","Content-Type": "application/json; charset=UTF-8",};const options = {method: "GET",headers: headerParameters,};async function getAllChannels() {try {const response = await fetch(url, options);printResponse(response);} catch (error) {printError(error);}}getAllChannels();
We call the conversations.list
endpoint, as specified in line 3, and print the result to the console.
Response fields
The response includes a channels
field that contains a list of all channels that have been created within the workspace, along with a cursor value for pagination.
Note: Visit this lesson to view the details of each element in the
channels
object.
Get the list of members from a channel
To get the list of members from a channel, we access the https://slack.com/api/conversations.members
endpoint.
Request parameters
Some important query parameters for the conversations.members
endpoint are as follows:
Parameter | Type | Category | Description |
| token | required | Authentication tokens carry the required scopes that govern the usage of different Slack applications and APIs. We usually pass these tokens as an HTTP Authorization header or as a POST parameter. |
| string | required | This parameter specifies the channel to which the message will be posted. It can be a public channel, a private group, or an IM channel (direct message). The value for this parameter can either be an encoded ID or a name of a channel. |
| string | optional | This parameter is a string of characters used to "point" to the next "page" of data. We paginate through collections of data by setting the |
| number | optional | The maximum number of items to return. Items fewer than the requested number may be returned. |
Let’s call the conversations.members
endpoint. Click the “Run” button to get a list of members of the given channel.
import fetch from "node-fetch";const url = new URL("https://slack.com/api/conversations.members");const headerParameters = {Authorization: "Bearer {{TOKEN}}","Content-Type": "application/json; charset=UTF-8",};const queryParameters = new URLSearchParams({channel: "{{CHANNEL_ID}}",});const options = {method: "GET",headers: headerParameters,};async function getChannelMembers() {try {url.search = queryParameters;const response = await fetch(url, options);printResponse(response);} catch (error) {printError(error);}}getChannelMembers();
Let’s look at the highlighted lines in the code widget shown above:
- Line 11: We provide the channel ID of the channel whose list of members we require.
- Lines 21–22: We provide the query parameters and call the
conversation.members
endpoint specified in line 3.
Response fields
The response includes a list of all channel members
along with a cursor value for pagination.
Get the replies to a message
To get the replies to a message, we access the https://slack.com/api/conversations.replies
endpoint. We specify the channel and the message timestamp to access its reply.
Request parameters
Some important query parameters for the conversations.replies
endpoint are as follows:
Parameter | Type | Category | Description |
| token | required | Authentication tokens carry the required scopes that govern the usage of different Slack applications and APIs. We usually pass these tokens as an HTTP Authorization header or as a POST parameter. |
| string | required | This parameter specifies the channel to which the message will be posted. It can be a public channel, a private group, or an IM channel (direct message). The value for this parameter can either be an encoded ID or a name of a channel. |
| string | required | This parameter specifies the timestamp of the message. |
| string | optional | This parameter is a string of characters used to "point" to the next "page" of data. We paginate through collections of data by setting the |
| boolean | optional | This parameter includes messages with the |
| string | optional | This is the latest timestamp. All messages before this timestamp will be included in the results. Its default is the current time. |
| number | optional | The is the maximum number of items to return. Items fewer than the requested number may be returned. |
| string | optional | This is the oldest timestamp. All messages after this timestamp will be included in the results. |
Let’s call the conversations.replies
endpoint. Click the “Run” button to get the replies to a certain message.
import fetch from "node-fetch";const url = new URL("https://slack.com/api/conversations.replies");const headerParameters = {Authorization: "Bearer {{TOKEN}}","Content-Type": "application/json; charset=UTF-8",};const queryParameters = new URLSearchParams({channel: "{{CHANNEL_ID}}",ts: "{{TS}}",});const options = {method: "GET",headers: headerParameters,};async function getMessageReplies() {try {url.search = queryParameters;const response = await fetch(url, options);printResponse(response);} catch (error) {printError(error);}}getMessageReplies();
Let’s look at the highlighted lines in the code widget shown above:
- Lines 10–13: We specify the channel and the timestamp of the message whose replies we want to get.
- Lines 22–23: We provide the query parameters and call the
conversations.replies
endpoint that is specified in line 3.
Response fields
The response includes a list of all replies to the specified message within the messages
property.
Note: Visit this lesson to view the details of each element in the
messages
object.