0

I'd like to download an attachment from the conversation via REST API (Circuit Sandbox)

If I query the Conversation Item, I can see the attachments and within that the fileID. Then, if I am logged with a user account who is a member of the conversation, I can run the following to download the attachment or paste it in the browser where I am logged to the sandbox:

''' start chrome https://circuitsandbox.net/rest/v2/fileapi?fileid=MyFileIdHere '''

And that works. Is there a way to achieve the same with a Bot via REST?

1 Answers1

1

A regular GET request will work.

curl https://circuitsandbox.net/rest/fileapi?fileid=<fileId> \
-H "Authorization: Bearer <ACCESS_TOKEN>"

and here is the REST notation.

GET rest/fileapi?fileid=<fileId> HTTP/1.1
Host: circuitsandbox.net
Authorization: Bearer <ACCESS_TOKEN>

The access token for a bot (client credentials grant) is obtained via OAuth 2.0:

curl https://circuitsandbox.net/oauth/token \
-d 'grant_type=client_credentials&client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>&scope=READ_CONVERSATIONS,WRITE_CONVERSATIONS'

REST notation:

POST /oauth/token HTTP/1.1
Host: circuitsandbox.net
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>&scope=READ_CONVERSATIONS,WRITE_CONVERSATIONS'
Roger Urscheler
  • 774
  • 2
  • 6
  • 11
  • Thanks again Roger, you are a legend. One thing on your reply: The URI is missing the v2 (as of today), also the REST notation is as you mention with GET, but it says POST: `https://circuitsandbox.net/rest/v2/fileapi?fileid=` `GET rest/v2fileapi?fileid= HTTP/1.1` In the case of a .txt file, I am getting the contents of the file, not sure which encoding it is but if I convert it to my system's default encoding I get a '਍' at the end which I can just remove easily. Question: If this was a .jpg or a .pdf file, would I get some kind of binary I can convert back locally? – Maverick Sevmont Aug 29 '19 at 02:18