Reputation: 646
I am creating one slack app. So there I need to fetch the team details. So I am calling users.list
API. But it's throwing me an invalid_auth
error.
I verified the token, my token is correct. When I am making request from slack's tester tab it's returning me all the users list of team.
You can see in below image I am getting the correct response but my code is throwing me invalid_auth
error.
Below is my code
import request from 'request';
const get = async (uri, token) => new Promise((resolve, reject) => {
request.get(`https://slack.com/api/users.list`, {
qs: { token }
}, (_, response) => {
//some code
});
});
What I am missing here?
As per Slack's documentation, Either the provided token is invalid or the request originates from an IP address disallowed from making the request.
In my case token is correct, so do I need to add IP Address of machine ? if so, where to add it then ?
Would be great if someone can help me out here.
Thanks in Advance!
Upvotes: 3
Views: 1228
Reputation: 349
I had a very similar issue and couldn't figure out what is it all about. Adding token to Authorization header didn't work too.
Everything worked in the Slack tester, but a request from React would always got invalid_auth
.
After inspecting the request that is sent from the Slack tester, I found it was sent as the form data. To mimic that, I did following:
const bodyFormData = new FormData();
bodyFormData.append("token", data.access_token);
bodyFormData.append("team", slackUser.data.user.team_id);
const slackTeam = await axios.post(
"https://slack.com/api/team.info",
bodyFormData,
{
headers: { "Content-Type": "multipart/form-data" },
}
);
That was successful.
Upvotes: 2
Reputation: 2861
There seems to be some changes in Slack API authorization.
Instead of passing token as query parameter,
pass it as authorization header.
Upvotes: 2