Integrating Salesforce with Box

I’ve been working on a project to integrate Salesforce and Box. This has been an interesting project to work on since it involves a bunch of brand new concepts to me such as future and batch apex and callouts. The goal of this project is to create a robust library to interact with Box using Salesforce apex code. I’ve posted my code on Github (also a first for me). Please take a look at my Github project, fork, make enhancements and contribute back. The code is free to use and modify. I haven’t attached an open source license to it yet, but feel free to do what you want with it.

Here’s the link: https://github.com/dhoechst/ApexBox

I’ll continue refining the code and hope to post some walk throughs of some of the code and how to use it.

 

Posting Files to Box.com using Jitterbit

I’ve been working on a big project to launch Box (www.box.com) at my company. Box is a fantastic web based file sharing service. I won’t go into details here, but check them out if you need to share files securely with others. My next few blog posts will focus on some of the aspects of that project.

One of the requirements was to automatically load files to Box shared folders. These files needed to included data from our ERP. For example, one file needed to list inventory levels and needed to be updated on a frequent basis. I definitely didn’t want to do this manually, so I turned to some automation. Jitterbit (www.jitterbit.com)  is a tool we use for all sorts for data integration, and it came through in this project as well.

The first step was to create an “application” in Box. There are detailed instructions here: http://developers.box.net/w/page/12923956/ApiOverview. Once you have your API key, you are ready for the next step of getting an authentication token as outlined at http://developers.box.net/w/page/12923915/ApiAuthentication. It is pretty easy to just use REST API calls right from a browser to get the token:

  1. Get a ticket by entering the following into your web browser (replace <apikey> with the one you obtained above: https://www.box.net/api/1.0/rest?action=get_ticket&api_key=<apikey>
  2. Use the ticket retrieved to authorize your application to your account: https://www.box.net/api/1.0/auth/<ticket>
  3. Finally retrieve the auth token: https://www.box.net/api/1.0/rest?action=get_auth_token&api_key=<apikey>ticket=<ticket>

Now that you have your auth token, you are ready to setup an upload process in Jitterbit. I’m assuming you already have some experience with Jitterbit and transformations. If not, Jitterbit has some great examples in their application help and online. You’ll need an http target setup with the following parameters:

  • URL (replace <authtoken> with your actual auth token, leave [folderid] as is: https://upload.box.net/api/1.0/upload/<authtoken>/[folderid]

Next, create a script to set some variables. $folderid is the id of the folder you want to upload to. You can get this by browsing to the folder in Box and looking for the 9 digit number in the URL. The filename should be changed to what you want.

$folderid = ‘123456789’;
$jitterbit.target.http.form_data = true;
$jitterbit.target.http.form_data.filename = “File Name.csv”;

Put this all together into an operation and run it. It should look something like Script->Source->Transformation->Target in the graphical editor. When it  runs, the transformation will be performed and the file added to the Box folder.