Reputation: 7730
I am following the following tutorial Slack API tutorial to post a message on slack. I already created Slack application and was able to use it with Incoming Webhooks now I would like to use API from python. So I tried:
import os
from slackclient import SlackClient
slack_token = 'xoxp-long-sequence-of-numbers'
sc = SlackClient(slack_token)
sc.api_call(
"chat.postMessage",
channel="my_test_channel",
text="Hello from Python! :tada:"
)
I got back the following error message:
{'error': 'missing_scope',
'headers': {'Access-Control-Allow-Headers': 'slack-route, x-slack-version-ts',
'Access-Control-Allow-Origin': '*',
'Access-Control-Expose-Headers': 'x-slack-req-id',
'Cache-Control': 'private, no-cache, no-store, must-revalidate',
'Connection': 'keep-alive',
'Content-Encoding': 'gzip',
'Content-Length': '105',
'Content-Type': 'application/json; charset=utf-8',
'Date': 'Fri, 05 Apr 2019 17:07:06 GMT',
'Expires': 'Mon, 26 Jul 1997 05:00:00 GMT',
'Pragma': 'no-cache',
'Referrer-Policy': 'no-referrer',
'Server': 'Apache',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload',
'Vary': 'Accept-Encoding',
'Via': '1.1 6529456e34a07353ab1987432f192696.cloudfront.net (CloudFront)',
'X-Accepted-OAuth-Scopes': 'chat:write:user',
'X-Amz-Cf-Id': 'wunHQVQpZicf-ynJO2u_n6CAQEGlYBH67ysu0fP1mfTEt86rRiAbrw==',
'X-Cache': 'Miss from cloudfront',
'X-Content-Type-Options': 'nosniff',
'X-OAuth-Scopes': 'identify,incoming-webhook',
'X-Slack-Req-Id': '990760fb-b110-43a1-86cb-fd4f8e2e34fa',
'X-Via': 'haproxy-www-km3w',
'X-XSS-Protection': '0'},
'needed': 'chat:write:user',
'ok': False,
'provided': 'identify,incoming-webhook'}
My channel name is literally: my_test_channel
. Probably I need to use different name, but how can I find it out?
UPDATE
So I found out encoded channel id and changed my script to:
import os
from slackclient import SlackClient
slack_token = 'xoxp-long-sequence-of-numbers'
sc = SlackClient(slack_token)
sc.api_call(
"chat.postMessage",
channel="CHXXXXXXX",
text="Hello from Python! :tada:"
)
but error back is still missing scope
Upvotes: 0
Views: 2855
Reputation: 86
It looks like its missing the user option according to the error ('needed': 'chat:write:user'):
sc.api_call(
"chat.postMessage",
channel="my_test_channel",
text="Hello from Python! :tada:"
user="U0XXXXXXX"
)
Upvotes: 2