Author: Shyam Kulkarni
What is Box Cloud Storage?
- Box.com is a secure, easy-to-use content cloud storage platform built for the entire content lifecycle from file creation and sharing to co-editing, signature, classification, and retention.
- Box stands out for its simplicity compared to other cloud storage platforms like Amazon Web Services, Google Drive, Microsoft’s Onedrive, iCloud, and Dropbox.
Use Case:
The use case goes as follows:
- A CSV file would be placed inside a folder in the Box.
- As the file is placed, MuleSoft Integration picks up the file and decides if the file placed is eligible for processing.
- If eligible, then download the file from the Box and perform integration with other systems, if use case demands (e.g can be upserting data to SalesForce).
- After completing the above process, next thing is to remove that file from the folder from where we picked it and upload it to the Archive folder. This implies that the file has been processed.
So, basically, if we look at this use case specifically from what we are really doing with MuleSoft and Box, here we are dealing with the following operations:
- Downloading/Fetching a file from Box.
- Uploading a file inside a folder present in the Box.
- Deleting a file from a folder present in the box.
For this we are going to use MuleSoft-provided out-of-box “Box Connector” and JWT configuration would be used.
So, I have divided this blog into two parts:
- Configuring Box
- Mule Box Integration
Configuring Box:
Following are the steps to be followed for configuring Box:
- Create a trial developer account by going to this link: https://account.box.com/login
- In the “Dev Console”, Click on “Create New App”, then select “Custom App”.


- Select the Authentication Method as “Server Authentication (With JWT)” and fill in the custom app name.

- Now, the Custom App is Created and the following page appears. Go to the “Configuration” tab and do these things:
- Copy the “OAuth 2.0 Credentials”. i.e Client ID and Client Secret (later used in a configuration).

OAuth 2.0 Credentials
Client ID:-- ugc419fobw42x3t64o4x24swp0qfpvhs
Client Secret:--
- Select “App + Enterprise Access” in the App Access Level section.

- Provide the required scopes as shown in the image i.e. (Read, Write, Manage Users, Manage Groups, Manage Enterprise Properties) in the “Application Scopes” section.

- Now, click on “Add a Public Key” in the “Add and Manage Public Keys” section and this can be added only if Multi-Factor Authentication is configured in Box.


- Now, what is to be added to the “Public Key” textbox? So, here we will be adding the public cert info. So, let us create a Keystore using the following command. Go to CMD -> Copy and Execute this command.
keytool -genkeypair -keystore mule-box-keystore.jks -dname "CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown" -keypass pass1234 -storepass pass1234 -keyalg RSA -sigalg SHA1withRSA -keysize 2048 -alias mule-box -ext SAN=DNS:localhost,IP:127.0.0.1 -validity 9999

- Once the Keystore is created, we can extract the public certificate from it using the following command:
keytool -exportcert -alias mule-box -keystore mule-box-keystore.jks -rfc -file public.cert


- Now, open the “public.cert” file using notepad and copy all the content from it and paste it into the textbox in Box’s configuration and verify and save it.


Save the information that we have configured for the “Configuration” tab.
- Now, head on to the “Authorization” tab and click on “Review and Submit”. After entering the “App Description”, click on submit and you will receive an email.





- Click on “Review App Details” and “Authorize” it.




Here, we can see “Authorization Status” and “Enablement Status” are set to “Authorized” and “Enabled” respectively.
- Now, if we go to the “General Settings” tab, we can see a “Service Account ID” is created – it kind of acts as an Integration User.

- Now, go to https://app.box.com/folder/0 and create a folder in the “Invite Additional People”, add the “Service Account ID‘, and give editor access.



- Also, create an archive folder inside the folder created earlier.

So, we have pretty much covered all the things in the “configuring box”, except adding the CSV file to it. We will do it when we will run our Mule application for demonstration.
Mule Box Integration:
Steps:
- Let’s create a Mule application. Start Anypoint Studio, create a new Mule Project, and add a “Box Connector” to your Mule Palette by searching for it on exchange and downloading it to your project.


- Add “mule-box-keystore.jks” file created earlier into src/main/resources folder.

- Now, let’s do the box-connector configuration with JWT:

You can configure the Client ID and Client Secret which we copied earlier.
Public Key ID: You get in the “Configuration” tab in box where we added public certificate info.
Entity ID: If you select “Box sub type” as “ENTERPRISE” then you can get the enterprise ID from the “General Settings” tab of Box.

Click on Test Connection and it should be working/successful.
- Since I have shared the JAR file of the Mule application here, I will just discuss the box connector operations being used and their configs.
- On the new file in the folder:
- This connector is placed in the source section, which gets triggered whenever a new file is placed in the folder present in the box.

- Here we have to configure the “Folder ID”, which is nothing but a way to know which folder is to be used for looking for new files being placed.

**Easy way to find the folder ID is to look at the URL in the top. It is the folder ID.
- It sends the following as the response whenever it picks up the new file uploaded to the box.
{
"created_at": "2022-12-02T03:28:42-08:00",
"modified_at": "2022-12-02T03:28:42-08:00",
"id": "1081036634933",
"name": "north_america_customers_file.csv",
"event_type": "ITEM_UPLOAD"
}
- -
“Id” here, refers to file ID of the “north_america_customers_file.csv” file, which is used in download file operation.
- Download File:
- This connector is used to fetch/download files from Box.

- It requires sending File ID i.e. which file is to be fetched.
- Upload File:
- This connector is used to upload the file to the Box. Here, in our use case, we are going to upload it to the Archive folder.

- In Attributes – Body, we need to pass a JSON object specifying the file name and folder ID where we need to upload a file.
e.g
{
"name": "north_america_customers_file.csv",
"parent": {
"id": "184555932384"
}
}
- File – The body is the raw data that needs to be passed inside the file.
- Delete File:
- This connector is used to Delete files from the Box’s folder.

- It expects a file ID to be passed i.e which file is to be deleted.
Note: If the file is uploaded successfully, it returns “201” as the status code whereas if the deletion of the file is successful, then it returns “204” as the status code.
The below is just to demonstrate this POC and how it works.
- So, after running the Mule application, we place the file in the folder in Box.

- MuleSoft picks it up and performs the download, uploads the file to the archive folder, and deletes it from the location from where it was picked up.
- On refreshing the page, we can observe that file is deleted and uploaded to the archive folder.

Archive Folder:

Mule Logs:

Mule Application Flow:

