Introduction
“It’s like a USB stick but on the internet, and you can access your files from anywhere.” That’s how someone first introduced Dropbox to me, and to be fair that’s exactly what it is. Well, it was then. It has more features now, but it’s pretty much the same, and that isn’t a bad thing. So why am I talking about Dropbox?
Because K2 has a new broker coming out in 2016 and it’s all about Dropbox. That’s awesome, because it lets K2 interact with a Dropbox account to send and retrieve files. This has loads of benefits: customers can drop files into a folder, retrieve documents very easily and access those files offline.
So this article explores what we can do with the Dropbox broker, and to make it even more interesting I’m also going to use some other services, like IFTTT.
So what is Dropbox?
Accessing files from cloud storage is commonplace now, and most of us use it to save documents, photos and so on. I do. I rarely keep anything on my laptop any more, because then I can get to it from any location and on any device. That’s what Dropbox does: it lets me access my files from anywhere, on any device. I can even have a special folder on my laptop that syncs certain files and folders with my Dropbox account.
Dropbox broker
The K2 Dropbox broker is very easy to set up, and hopefully it’s a new way to make it easier for people to hook up to new services, as there’s no longer any need to use the ServiceObject Tester to tell K2 about Dropbox.
Creating a Dropbox app
You need a Dropbox account, which you can get for free. You also need to create a Dropbox app in your account. To do that, follow these steps.
- Log into https://www.dropbox.com/developers/apps.
- Click on ‘Create App’.
We’re now on the app creation page. Here we choose whether to create a widget for a website or to actually use Dropbox’s web services.
- Select ‘Dropbox API app’. Some more options will appear. Now we decide how the app will interact with Dropbox: whether it’s limited to the files and folders it creates, or has access to all the files and folders in the account. We also decide which file types the app can see.
- Select ‘No’ for ‘Can your app be limited to its own folder?’.
- Select ‘All file types’.
- Importantly, give the app a name!
- Click on ‘Create app’.
- Now that the app has been created, copy the ‘App Key’ and ‘App Secret’, which we’ll need later for the broker. In the ‘OAuth 2’ section, put in the OAuth token address of your K2 server. It will be something like https://k2.[domainname]/identity/token/oauth/2.
OK, so we’ve created a Dropbox app. Now we need to tell K2 about it.
Registering the Dropbox app with K2
- Go to the K2 Designer and expand ‘All Items’.
- Expand ‘System’, ‘Management’, ‘Features’, ‘Dropbox’, ‘Forms’.
- Run the ‘Dropbox.main’ form.
The next stage is really simple. We need the keys we copied from the Dropbox app.
- Enter a suitable name, like ‘DropBox’.
- Enter your ‘App Key’ into the ‘Client Id’ box.
- Enter your ‘App Secret’ into the ‘Client Secret’ box.
- Click on ‘OK’.
K2 then starts creating the service instance for your Dropbox app, checking it can access the app and that the correct keys have been given.
During setup a popup will say it’s going to redirect you to Dropbox for authorisation.
Once you’ve logged in, it redirects you back to K2 to tell you it was successful. It then carries on creating the Dropbox SmartObjects and adds the smart wizards so you can use them in the workflow designer.
Click on ‘Done’ and that’s it. We’re now ready to build an app in K2 that integrates with Dropbox.
The original post had a video going through these steps of creating the Dropbox app and connecting Dropbox to K2.
Exploring the Dropbox SmartObjects
So we’ve seen how to configure Dropbox and K2, but what can you do with the Dropbox SmartObjects? Let’s look at each one. By default we get the following SmartObjects:
- Folder
- File
- Items
- Shared Link
- Thumbnail Size
- Thumbnail Format
The last two are just lookup objects, so I’m leaving those out.
Folder SmartObject
The Folder SmartObject lets K2 manage the folders in the Dropbox account. It lets K2:
- Create a folder, both parent and child folders
- Delete a folder
- List all the folders at a particular level
- Move folders around
- Copy folders
- Search for folders matching keywords
There’s no integer ID field or GUID as the primary key. Instead Dropbox uses the path of the folder, and this path string is also used by all the other Dropbox SmartObjects where a single row is returned.
File SmartObject
The File SmartObject lets K2 manage the files in the root of the Dropbox account, and in its folders and subfolders. It lets you:
- Upload a file
- Load File: load the details about the file
- Load File without Content: load the details about the file, but not the content
- Restore: restore a document from a previous version
- Move: move a file from one folder to another
- List: list all the files in a given location
- Search
- List Revisions: show all the revisions for a given file
- Delete: delete a file
Item SmartObject
This SmartObject shows all the details about a file or folder at a particular location. It supports these operations:
- Load: show the details about a particular folder or file
- List: show all files and folders at a location, optionally including deleted files
- Search: use a keyword to find any matching files or folders
Shared Link SmartObject
This SmartObject gets a shared link for a particular file or folder.
Building a K2 app with Dropbox
Now that we have the SmartObjects, we can start building an app that uses them. The app uses this functionality:
- Creating a folder
- Copying a file from a SharePoint 2013 document library to Dropbox
I’m also using Dynamics CRM to give the demo some context. It wouldn’t be one of my demos without some CRM data!
The app creates a repository for a customer. We create a folder for the customer, named after the account GUID. Once we have the folder, we select which documents from our SharePoint library we want to move into the repository for the customer to access. Once that’s done, the customer receives an email (or it could be an SMS message) with a link to the content.
The original post had a video going through the steps of building the app.
IFTTT (If This Then That)
So what is IFTTT? It’s a cloud service that lets users create chains of simple conditional statements, called “recipes”, which are triggered by changes in other web services such as Gmail, Dropbox, Facebook and OneDrive.
OK, but why use it with Dropbox and K2? Partly because I can, but more importantly because I think it shows how different services can be used together to build a really interesting application.
IFTTT, Dropbox and K2 demo
In this demo I created an IFTTT recipe so that when I send an email with an attachment, it creates a folder in Dropbox named after the email subject and drops the attachment into it. It also takes the body of the email and puts it into a text file. The subject happens to be the CRM account number, so we can see the documents in a K2 SmartForm. In the demo, when you create a purchase order and select an account, a tab appears showing all the related documents from the matching folder.
Extending Dropbox with K2
Dropbox also supports webhooks, so we could take this further: every time there’s a change, Dropbox could post to the K2 server, which would then start a workflow. That’s the same way we can have an SMS message or a sensor start a workflow.
IFTTT can also make and receive web requests using its Maker channel, which opens up a whole range of integration possibilities. That’s something I’ll be exploring later in the year.
Conclusion
The Dropbox broker is a brilliant addition to the growing list of out-of-the-box brokers that come with K2. Dropbox is a popular service, and it gives businesses another option for storing and accessing documents rather than relying only on SharePoint document libraries. The broker will be out in 2016 and I for one can’t wait to see what people do with it, especially with services like IFTTT that can integrate with Dropbox, and in turn with K2.