Send API request arguments as JSON
Description
The Slack Web API now supports JSON bodies for write requests.
The Authorization header is used to trigger this new behavior. This client should adopt this functionality. The main advantage is a security beat practice for getting the token out of the request location/path.
What type of issue is this? (place an x in one of the [ ])
- [ ] bug
- [x] enhancement (feature request)
- [ ] question
- [ ] documentation related
- [ ] testing related
- [ ] discussion
Requirements (place an x in each of the [ ])
- [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
- [x] I've read and agree to the Code of Conduct.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Is there a common use case where someone would be appending items to the form params outside of the client's dict wrapper? Would it make sense to support both or just convert to JSON POST in lieu of form params?
I'm in favor of just switching over, but I verified that we can pass the token in header with both post types without worry.
@aoberoi ☝️
@roach this is partially subjective but I think getting the arguments out of the URL and into the body is just “cleaner”.
The serialization is less tricky and easier to read (escaping JSON serialized strings and then serializing again as query params is very treacherous and un-readable). Also, super long URLs are a pain for tools like Steno.
I agree, I just can't think of a valid case where someone would try to modify it directly. I'll get this change out this week.
Logging: its not modification but it is common to have intermediaries (in process like New Relic or out of process like a proxy) that capture the URL. As is, that contains sensitive data (the token) and is hard to read (the rest of the arguments serialized).
Keeping track of which endpoints support JSON POST will require either maintaining a map or pulling in the API Spec as a dependency.
I'm thinking I'll pull in the API Spec JSON. https://github.com/slackapi/slack-api-specs/blob/master/web-api/slack_web_openapi_v2.json
What is the ETA for this being complete? I ABSOLUTELY need the JSON extensions to Slack messages (message coloring, etc). To do this, I am assuming that setting the Content-type header to application/json is necessary, but I still see no entry point to do this.
@misterkbar can you help me what you mean by "JSON extensions"?
From your description, I think you mean attachments, which support the color bar on the side of a message. This library already supports sending messages with attachments. For example, to use the chat.postMessage Web API method to send a message with an attachment, you'd do something like this:
from slackclient import SlackClient
slack_token = os.environ["SLACK_API_TOKEN"]
sc = SlackClient(slack_token)
sc.api_call(
'chat.postMessage',
channel='C0XXXXXX',
text='Hello from Python! :tada:',
attachments=[{
'fallback': 'Required plain-text summary of the attachment.',
'color': '#36a64f',
'text': 'This text is inside the attachment.'
}]
)
Pro tip: You can use the Message Builder to play around with the attachment properties and achieve the design you're hoping for.
JSON support has been added in v2. I'm closing this issue as there are no current plans to make any changes to this in v1. I'd encourage everyone take a look at our migration guide for more details.