I'm having trouble determining the correct API endpoint and the correct API fields to use to upload a file to a channel.
I have seen issue #1693 on Github for a similar question and a few posts about it on here. The only answers provided are links to the Javascript and the Go driver. I tried reverse engineering those drivers to figure out what fields are required to do this to no avail.
I've also read in the documentation on the MM website that the new API Version is directly compatiable with the Slack API. I've tried to port this code over, no luck.
I think I am almost there. Could anyone give me a hand? I am using Python 2.x with the requests module.
import re
import requests
import json
from pprint import pprint
def authenticate():
payload = { "name": "name", "login_id": "username", "password": "password" }
headers = { "content-type": "application/json" }
s = requests.Session()
r = s.post("https://mmdomaingoeshere/api/v3/users/login", data=json.dumps(payload), headers=headers, verify=False)
authToken = r.headers.get("Token")
return authToken
def postFile(token, file_):
headers = { "Authorization": "Bearer %s" % (token), "Accept": "application/json", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en" }
files = {"file": open(file_, 'rb'), "filename": file_}
data = {"channel_id": "45w79egbpfy4iq15ug7cn6ai8c"}
r = requests.post("https://mmdomaingoeshere/api/v3/teams/f74asir3gbnyfjcysn1b36iube/files/upload", headers=headers, files=files, data=data, verify=False)
pprint(r.json())
if __name__ == "__main__":
token = authenticate()
postFile(token, "testFile")
Here's the output
{u'client_ids': [], u'filenames': []}