Log in
Hot & Trending on FMT

DropBox to FileMaker Part 1

Featured DropBox to FileMaker Part 1

DevCon 2015 has come and gone, and certainly one of the highlights for me was building an app that integrates Dropbox and FileMaker. I had previously discovered that the FileMaker Script Step Insert From URL works with dropbox URLs. In fact, this was the primary motivation for speaking about Insert From URL at DevCon.

The original goal was to do a simple demo inserting a file stored on Dropbox into a FileMaker container field. This worked fine, but had a glaring practical limitation: the only URLs you can predict, and therefore program, are the ones in the Dropbox public folder. The download strings that Dropbox generates outside the public folder are, for all intents and purposes, random.

After a little research, I discovered that Dropbox had a relatively simple http API, and that through it you could get these download URLs. I also noticed there was a lot of other stuff the Dropbox API could do and decided to go a little deeper! How much could we do with Dropbox using the Insert From URL script step? Since Insert From URL works in FileMaker GO, I took the approach of building a mobile first app to test the question.

We’re happy to share the resulting demo file on our downloads page in the DevCon 2015 Demo Files section. The first thing you’ll need to do to play around with this file is to get it authorized.

Registering Your FileMaker App for OAuth

The Dropbox API requires you to go through an authorization process using OAuth2.0. Essentially, you need to get an Access Token from Dropbox. Once you have the Access Token, you need include it as a parameter in the API’s GETs and POSTs to retrieve data from Dropbox. The process of getting the token with DropBox is similar to other APIs I’ve used, but has a few features that make it work well within FileMaker. However, before you can begin attempting to authenticate to DropBox, you need to register your “app” with DropBox. This is free, but does require a DropBox account. Setting up your app is done here. Once you’ve registered your app, Dropbox will provide you with an “App Key” and an “App Secret”. These are used in the OAuth process and we have fields for these values in the Settings section of our sample file.

Once you have the App Key and Secret entered, you can begin the OAuth process.

OAuth Via the FileMaker Web Viewer

Like many OAuth implementations, the first step in authenticating is to go to a web page provided by Dropbox where you manually enter your Dropbox credentials and Authorize the App. These steps are meant to be done by humans, as being able to just pass these credentials via POST would make it considerably easier to “crack” the process.

Log Into Dropbox via Web Viewer. The URL for the Web Viewer is specific to the App that you registered and looks like this:

"https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id="& DropBox::AppKey

The response_type=code parameter is nice because it specifies that we want to receive the “code” right in the web viewer itself. Typically an Oath flow will require a CallBack URL, and the code will be POSTed to that URL where it could be retrieved in a typical web app. However, we have no way of doing that in our Web Viewer, and we’d be stuck at this point. Fortunately, we can get our code as text in the web viewer and copy and paste it into our FileMaker field!

 Insert From URL

This code is not our Access Token, however. Once we have this code, we need to do a POST to Dropbox with this code, and our App Key and App Secret. The code is only good for a short time, and Dropbox is expecting this POST soon after the code is generated. If this POST is successful and the code, key and secret all check out, then DropBox will return an Access Token and we can begin to make actual API calls to DropBox. This POST to get the Access Token is the first time that we use Insert From URL, and the URL we create for this looks like:

 

httpspost://api.dropbox.com/1/oauth2/token?code=<Code From Web Viewer>&grant_type=authorization_code&client_id=<App Key>&client_secret=<App Secret>

A successful POST returns a response in JSON format that looks like this:

{"access_token": "ABCDEFG", "token_type": "bearer", "uid": "12345"}

We can then use our JSON parsing tools (more on this in an upcoming post) to extract the Access Token and we’re in business! We can now make our first call to retrieve the top level Dropbox folder and display the contents in FileMaker.

The Access Tokens do not expire, but they can be revoked either via the API or from the App Console. Care should be taken with these Access Tokens as they are the keys to the castle!

Stay tuned for more on using the Dropbox API with our demo file coming soon!

SeedCode

SeedCode is the leading extensions developer for FileMaker Pro, the cross platform database and app creation environment from Apple. Our software enables developers to make more efficient and powerful apps for iPad, iPhone, and desktop.

Website: www.seedcode.com/