Upload file via curl / webhook

Hi.
I’ve created a webhook for incoming messages and it’s working fine using the example payload.
However I’d like to upload an image, instead of referring it as an external URL.

This is working form me:

curl -X POST -H ‘Content-Type: application/json’ --data ‘{“text”:“Example message”,“attachments”:[{“title”:“Rocket.Chat”,“title_link”:“<some_link>”,“text”:“Rocket.Chat, the best open source chat”,“image_url”:“<some_address>/someimage.png”,“color”:“#764FA5”}]}’ https://myrocket.onpremises.local/hooks/

I tried using the example here but it didn’t work (replacing all info with my own, including the token and user id):

{“status”:“error”,“message”:“You must be logged in to do this.”}

Going back to the json example, what tag I should use to refer to a local file and upload it?
I searched for a guide of valid tags but I haven’t found any.

Thanks!

Hi! Sorry for the delay here :frowning:

Some threads were not appearing on my recent list.

Were you able to fix this?

While you cannot upload files using the webhooks, you can always leverage the APIs for that.

The error you got is about not begin able to validate the userid and token. Instead of loging and getting the user and token, I suggest you to generate a PAT (Personal Access Token) that will not expire get revoked by a subsequent login.

Hi, thanks for replying.
Ok, after generating a PAT, I’ve tested this and it works as expected:

curl "https://myrocket.onpremises.local/api/v1/rooms.upload/GENERAL" -F "file=@/path/to/test_img.jpg" -F "msg=This is a message with a file" -F "description=Simple text file" -H "X-Auth-Token: <my_pat>" -H "X-User-Id: <my_uid>"

I just had some trouble trying to find specific rooms’ RID other than GENERAL. I had to inspect my request on the browser, under Network. Probably there’s an easy way to find them that I’m missing?

Thanks a lot for your help!

Hi! Glad it worked out. :slight_smile:

There is a better way. When you edit a room, you can get it’s ID from the url:

This is also true for users or Omnichannel Chats too

Perfect! Thanks again for your help!

1 Like