Hey there,
i am working on some scripts to automate setting up RocketChat during deployment. I am really happy to see the possibility to set assets being added to the REST API. However the docs are not really clear and so far i did not succeed to actually upload an asset and set it.
Based on code i found on github (https://github.com/jadolg/rocketchat_API/tree/master/rocketchat_API Thanks!) i wrote a minimal wrapper around the REST API only implementing the endpoints that i need.
Logging in etc. all works fine and also a bunch of other methods i implemented already work fine (to set up channels and other settings).
So now i want to set up the logo and favicons. Here is the code to the post method i am using:
def post(self, method, files=None, use_json=True, **kwargs):
reduced_args = self.__reduce_kwargs(kwargs)
# Since pass is a reserved word in Python it has to be injected on the request dict
# Some methods use pass (users.register) and others password (users.create)
if 'password' in reduced_args and method != 'users.create':
reduced_args['pass'] = reduced_args['password']
if use_json:
return requests.post(
self.server_url + self.API_path + method,
json=reduced_args,
files=files,
headers=self.headers,
verify=self.ssl_verify)
else:
return requests.post(
self.server_url + self.API_path + method,
data=reduced_args,
files=files,
headers=self.headers,
verify=self.ssl_verify)
And here is the code i played with to upload and set the logo:
def set_asset(self):
response = self.post(
"assets.setAsset",
use_json=False,
files={
'logo.png':
open(r"C:\Users\tkaufmann\Pictures\rocketeer.png", 'rb')
},
logo="logo.png")
return response
I tried various combinations and settings but i am getting error code 400 (bad request) no matter what i try. I read the docs but i am unsure how to get this to work. Any help would be greatly appreciated.
Cheers,
Thorsten