So you want to integrate your Box folders and files with your Ruby on Rails applications. There are a ton of reasons you might want to do this, but I am pretty sure if you landed here you might have an idea about why you are.
The Box.com API is fairly large and has a lot of amazing docs, but it can be difficult to figure out where to start or how you might use it to do things like, create folders from your Rails app or display files from a folder in your App’s UI.
In this post we will cover:
In Part 2 we will cover:
Your first requirement is to either create a new account or have an admin level permission on a Box account.
After we have our account setup we need to create a new application on our Box account. We will use it to integrate with our Rails application. This is a common way APIs are set up these days. The application is essentially a place where you store all the settings and credentials you will use for you communicating with the Box API.
Next, we are going to go to the dev console via the left menu bar:
From the dev console, we will need to create a new app.
We are given a choice of types of applications to create. We will be creating a “Custom App” as it will best support us for doing async tasks from the server.
Our Authentication Type will need to be “OAuth 2.0 with JWT” (server-side auth). Let’s give our app a name and move on to “view our app”.
Awesome! We set up our box integration app. We still have two more things to do in Box in order to be prepared for our Ruby on Rails App.
First, we need to generate a public and private key-pair for our app to use. This will prompt our 2-factor auth code.
This should have downloaded a JSON file with all the keys and such we need to integrate with our Rails app. Hold onto this file, keep is safe we will use it soon. If anyone were to get access to these keys they would be able to access your entire box account.
Next, we need to authorize this app to make API calls. Seems obvious I know, but this is so developers like us can build apps and the system admin can decide whether or not to approve it.
We will need to go back to our main Box account home page and click on the admin console and then the app tab.
Scroll down to the custom applications section and click on Authorize New App.
Boom! We are all set up on Box.
Let’s dive in:
It will look something like this:
Our migration should look like this:
It will look like this:
NOTE: I added a parent folder ID that the folder will be created in. This helps contain all these project folders in one place for me, but you can leave it as the root folder if you would like.
Great, we did it! We now have Box integrated with our backend application to create and reference a new folder for all of our projects on our app!