Slack integration

  • 1
  • Question
  • Updated 1 month ago
Hi All,
I wish to have a slack integration with a bot.

My vision is to send slackbot a message like:
"@Sharefile request ZD#1122"
And it will create a folder under X with the name ZD#1122 and will generate a request link automatically.

What are the needed tasks I have to follow?

( I'm learning since I'm not a coder )
Photo of Tomer Ben Arye

Tomer Ben Arye

  • 5 Posts
  • 1 Reply Like

Posted 3 months ago

  • 1
Photo of Michael Berrier

Michael Berrier, Employee

  • 123 Posts
  • 24 Reply Likes
Hi Tomer,

You can start here:
http://api.sharefile.com/rest/

Check out the Getting Started links, generate an API key for yourself, and look over our SDKs and endpoint documentation.

Based on your example, you're probably interested mainly in endpoints for manipulating Items (for creating folders and performing uploads) and Shares (for creating links to those):
http://api.sharefile.com/rest/docs/resource.aspx?name=Items
http://api.sharefile.com/rest/docs/resource.aspx?name=Shares

We can't really help out with the fine details on how to build a Slack bot, but the above will be a great start for building the core logic of the interaction with ShareFile.

Michael
Photo of Tomer Ben Arye

Tomer Ben Arye

  • 5 Posts
  • 1 Reply Like
Hi Michael,

I learned a lot with your API docs. but I still have some questions.
( it appears that it's easier to learn with the "Chrome Developer Tool" always ON.

I'm using Postman right now and I'll make the br later on when I'll summarize all together :-)
As said, I need the following workflow:  steps 1 and 2 are straightforward, step 3 is the problematic one. 

1. Create a folder under a specific shared folder.
2. Create a "request link" within that Folder by link.
3. Create a "ShareLink" ( download link ) for people w/o the credentials


Regarding step1: (Create a folder)
I know I need to POST

POST
https://xyz.sf-api.com/sf/v3/<b>Items</b>(<b>fo...5</b>)<b>/Folder</b>
BODY: {'Name':'ZD#TEST1','Description':'ZD#TEST1'}
#Description=notes in ShareFile ( not needed - leave '' )

Response:
Getting Id
   "Id": "fo...d0",

I'm taking the id from "step1 response" into step2.

Regarding step2: (Create a "request link")
I'm taking the output of the Uri.


https://xyz.sf-api.com/sf/v3/Shares?notify=true&direct=false
# notify=by email ( send email to user - true/false )
# direct=make sure the end user is inserting his name + lastname ( true / false )

POST Body: {"ShareType":"Request","Title":"File Request","Parent":{"Id":"fo.......d0"},"RequireUserInfo":false,"ExpirationDate":"9999-12-31T23:59:59.999Z"}

response:
{"AliasID":"r22..a","ShareType":"Request","Title":"File Request","HasSentMessage":false,"SentMessageTitle":"","RequireLogin":false,"RequireUserInfo":false,"CreationDate":"2018-06-02T22:02:18.14Z","ExpirationDate":"9999-12-31T23:59:59.9999999Z","MaxDownloads":-1,"TotalDownloads":0,"IsViewOnly":false,"TrackUntilDate":"0001-01-01T05:00:00Z","SendFrequency":0,"SendInterval":0,"LastDateSent":"0001-01-01T05:00:00Z","IsConsumed":false,"IsRead":false,"IsArchived":false,"SendTool":"","SendMethod":"","Uri":"
https://xyz.sharefile.com/r-r2...07a"...":"","... full control","AccessRightType":"FullControl","odata.type":"ShareFile.Api.Models.ShareAccessRight","Id":""},"IrmProtected":false,"odata.metadata":"
https://xyz.sf-api.com/sf/v3/$metadat...","...}


link to be sent
https://xyz.sharefile.com/r-r2...7a&nbsp;

Step2 done!


Step3: (Create a "ShareLink")

I didn't catch if I need to make OPTION POSTS and then POST request.  can you help me with that, please?


From the Devtools, I saw that those requests are sent:

a. POST request: https://xyz.sf-api.com/sf/v3/Capabilities

b. OPTIONS request: https://xyz.sf-api.com/sf/v3/Shares/AccessRights(Link)

c. POST request: https://xyz.sf-api.com/sf/v3/Shares/AccessRights(Link)

d. OPTIONS request: https://xyz.sf-api.com/sf/v3/Items(fo...d0)?%24select=StreamID&canCreateRootFolder=false&fil...

e. POST request: https://xyz.sf-api.com/sf/v3/Items(fo...d0)?%24select=StreamID&canCreateRootFolder=false&fil...

f. OPTIONS request: https://xyz.sf-api.com/sf/v3/Shares?notify=false&direct=false

g. POST request: https://xyz.sf-api.com/sf/v3/Shares?notify=false&direct=false

( response ("AliasID":"s0...b8","ShareType":"Send","Title":"ZD#TEST",......"Uri":"https://xyz.sharefile.com/d-scb8",....)"}

From g , I'm getting the Uri to be sent.

Do I really need to do seven steps to get a "share link" for specific folder so anyone with the link could download the data inside that folder?
(Edited)
Photo of Tomer Ben Arye

Tomer Ben Arye

  • 5 Posts
  • 1 Reply Like
See the last 7 steps:
(Edited)
Photo of Michael Berrier

Michael Berrier, Employee

  • 123 Posts
  • 24 Reply Likes
Tomer,

The OPTIONS calls you observe are CORS pre-flight requests. They usually happen when JavaScript on a page makes an HTTP request cross-origin (to a different domain), which is the case when our web app on sharefile.com calls our API on sf-api.com. More info about pre-flight requests here if you're interested:
https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

In any case, you should not typically need to issue an OPTIONS call yourself.

Next, let me caution you that the ShareFile web app tends to send all (non-pre-flight) requests as POSTs, along with an X-HTTP-Method-Override header that may change the actual method on the fly to a GET, DELETE, PATCH, PUT, etc. So if you're observing traffic from the web app to emulate in your own implementation, look out for that header. Some of the calls you identified are actually GETs -- not POSTs -- under the covers.

Finally, you should be able to accomplish what you want with only the call from step g in your last reply, assuming the folder or item you want to share is known to exist already. With appropriate arguments, POST /sf/v3/Shares will create the link you want. If your goal is to make the link anonymously accessible by anyone who navigates to it, then make sure that the request includes "RequireLogin": false and "RequireUserInfo":false.

Michael
Photo of Tomer Ben Arye

Tomer Ben Arye

  • 5 Posts
  • 1 Reply Like
Thank you very much, Michael
That was exactly what I needed!.
Photo of Tomer Ben Arye

Tomer Ben Arye

  • 5 Posts
  • 1 Reply Like
Hey Michael,

I wrote the script but I didn't understand one thing.

1. I'm creating a folder, creating a request link and a download link.
All done, I'm getting their URL's

2. When I'm trying to make the same directory, I get 409 - Conflict ( which is OK )
Now, Do I really need to repeat the steps above ( request and download ) or I can get it somehow?

The reason I'm asking is when I'm repeating those two processes, I'm getting new URL's.
a. I can see it's not affecting the previous links - which is good!
b. The API call I'm using is .sf-api.com/sf/v3/Items/AdvancedSearch I might need to use something else?

Thanks again.
Photo of Michael Berrier

Michael Berrier, Employee

  • 123 Posts
  • 24 Reply Likes
Tomer,

If you want to reuse existing share links, the simplest solution is probably to store the source folder IDs / names and the share URLs on your end. If you run into a conflict, you could consult that list to reuse the same links you've already built.

Michael