'slack api invalid auth error

I was using the slack python api to build a chatbot but while calling the api I am getting an invalid_auth error in the user.list. The token I am using is the Bot User OAuth Token provided by slack.

import slackclient

ADAM_SLACK_NAME = os.environ.get('ADAM_SLACK_NAME')
ADAM_SLACK_TOKEN = os.environ.get('ADAM_SLACK_TOKEN')

adam_slack_client = slackclient.SlackClient(ADAM_SLACK_TOKEN)

print(ADAM_SLACK_NAME)
print(ADAM_SLACK_TOKEN)

is_ok = adam_slack_client.api_call("users.list").get('ok')
print(is_ok)

The output I am getting from is_ok is False. Here is the result of the API call to users.list:

{'ok': False, 'error': 'invalid_auth', 'headers': {'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '55', 'Connection': 'keep-alive', 'Date': 'Tue, 31 Jul 2018 16:22:03 GMT', 'Server': 'Apache', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Referrer-Policy': 'no-referrer', 'X-Content-Type-Options': 'nosniff', 'X-Slack-Req-Id': '9b0519c0-d3b9-4da6-9175-9346a08deed9', 'X-XSS-Protection': '0', 'X-Slack-Backend': 'h', 'Vary': 'Accept-Encoding', 'Content-Encoding': 'gzip', 'Access-Control-Allow-Origin': '*', 'X-Via': 'haproxy-www-surh', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 66e5950d2a2f44a694f4d9d434e9a3c9.cloudfront.net (CloudFront)', 'X-Amz-Cf-Id': 'ZWMCmqhdO8pMsbWXbnL63QppUbFSvzodLtTyjQ-4cB35107QqSowZQ=='}}

How can I resolve this?



Solution 1:[1]

In my case, I was using nodeJS for making oauth.access call and I got this error. Turned out i missed encodeURIComponent for SLACK_REDIRECT_URI. Hope that helps someone.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Saravanan S