List Conversations and Users

Learn to use Slack API calls to get users' data in the workspace.

Let’s look at the following endpoints in this lesson:

  1. users.conversations: This endpoint lists the conversations the requesting user may access.
  2. users.list: This endpoint lists all users in a Slack team.

Get a list of conversations

To get a list of conversations, we’ll access the https://slack.com/api/users.conversations endpoint. We can use this endpoint to know the number of conversations in which the application is engaged.

Request parameters

Some important query parameters for the users.conversations endpoint are as follows:

Parameter

Type

Category

Description

token

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.

cursor

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 cursor parameter to a next_cursor attribute returned by a previous request's response_metadata.

limit

string

optional

The maximum number of items to return.

Let’s call the users.conversations endpoint. Click the “Run” button to receive a list of conversations the app can access.

Press + to interact
import fetch from "node-fetch";
const url = new URL("https://slack.com/api/users.conversations");
const headerParameters = {
Authorization: "Bearer {{TOKEN}}",
"Content-Type": "application/x-www-form-urlencoded",
};
const options = {
method: "GET",
headers: headerParameters,
};
async function getConversations() {
try {
const response = await fetch(url, options);
printResponse(response);
} catch (error) {
printError(error);
}
}
getConversations();

On line 17, we call the users.conversations endpoint to get the conversations in which the application (or the authorized user) is engaged.

Response fields

The response includes a list of channels the application can participate in.

Note: Visit this lesson to view the details of each element within the channels property.

Get a list of users

To get a list of users, we access the https://slack.com/api/users.list endpoint. The API will respond with the list of users in the given workspace.

Request parameters

Some important query parameters for the users.list endpoint are as follows:

Parameter

Type

Category

Description

token

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.

cursor

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 cursor parameter to a next_cursor attribute returned by a previous request's response_metadata.

limit

string

optional

This is the maximum number of items to return.

Let’s call the users.list endpoint. Click the “Run” button to receive the list of users in the workspace as a response.

Press + to interact
import fetch from "node-fetch";
const url = new URL("https://slack.com/api/users.list");
const headerParameters = {
Authorization: "Bearer {{TOKEN}}",
"Content-Type": "application/x-www-form-urlencoded",
};
const options = {
method: "GET",
headers: headerParameters,
};
async function getUsers() {
try {
const response = await fetch(url, options);
printResponse(response);
} catch (error) {
printError(error);
}
}
getUsers();

On line 17, we call the users.list endpoint to get the list of users that are present or were present in the workspace.

Response fields

The response contains a list of all members of the workspace.

Note: Visit this lesson to view the details of each element within the members property.