Author: Nishant Banga
Box is a cloud computing business which provides file sharing, collaborating, and other tools for working with files that are uploaded to its servers. Users can determine how their content can be shared with other users.
Box enables quick access to files from any device, so they are free to be productive wherever they are. Plus, Box’s cloud storage ensures you always have an online backup handy and can access data from anywhere.
PROBLEM STATEMENT: To connect to client’s box storage and access files and folders to further process the data. Here we will see how to build a connection with box cloud from MuleSoft.
REQUISITES: Access to box cloud storage and Developer account on box.
STEPS TO BUILD CONNECTION:
- Go to the box developer console and create a new app.

- After creating the app, click on configurations to get the Client ID and secret. Also, you have to add the redirect URI there.

- Set redirect URI as “http://localhost:8081/oathcallback” (can be anything, but we have to add the same in the studio as well). A redirect URI, or reply URL, is the location that the authorization server will send the user to once the app has been successfully authorized and granted an authorization code or access token.
- Copy the client ID and secret.
- In the studio you can add a Box connector by searching it in the exchange as “mule-box-connector” (I have used version 4.0.1).
- Add the box connector configuration in the global file with following set of values:

- localCallbackUrl will be your Http listener configuration name.
- ClientId- secret is what you copied from the app in the developer console.
- externalCallbackUrl will be the redirect URI you entered in the box developer console.
Rest all values are the same and can be used as it is.
- Logout from the developer console of the box.
- Deploy your application and before hitting any endpoint, hit localAuthorizationUrl from browser. It will ask to grant some access. This is a one time process.
Upon doing this, box will recognize our host to be secure for the user and will grant any transactions in future to flow without any authorization issues. - Connection has now been established successfully.
- Now you can hit any endpoint of your application.
POC for Getting Folder Contents:
This POC will use the “Get Folder” component which is used to get details of the folder and it’s content in json format. We just have to pass the folder ID in the configuration (it can be seen in the end of URL).



box-demo.xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mule-box-connector="http://www.mulesoft.org/schema/mule/mule-box-connector" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/mule-box-connector http://www.mulesoft.org/schema/mule/mule-box-connector/current/mule-mule-box-connector.xsd">
<flow name="box-demo-blogFlow" doc:id="387b7768-9bd2-46a6-a10f-331de305d534" >
<http:listener doc:name="HTTP Listener" doc:id="f7d76521-4dc3-4209-a504-a763f7b76e03" config-ref="HTTP_Listener_config" path="/demo"/>
<mule-box-connector:get-folder doc:name="get files present in folder" doc:id="d4de0460-3b6f-4028-953c-aa6461528588" config-ref="Mule_box_connector_Config" folder-id="${common.folder-id}"/>
</flow>
</mule>
global.xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:salesforce-analytics="http://www.mulesoft.org/schema/mule/salesforce-analytics"
xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:secure-properties="http://www.mulesoft.org/schema/mule/secure-properties"
xmlns:mule-box-connector="http://www.mulesoft.org/schema/mule/mule-box-connector"
xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/mule-box-connector http://www.mulesoft.org/schema/mule/mule-box-connector/current/mule-mule-box-connector.xsd
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="df459656-9a9f-4153-9f56-d5a11f15cb19" >
<http:listener-connection host="${http-listener.host}" port="${http-listener.port}" />
</http:listener-config>
<configuration-properties doc:name="Configuration properties" doc:id="25d7d0e7-2573-4ffc-8f65-50c657cdc5f4" file="application-properties\config-${env}.yaml" />
<mule-box-connector:config name="Mule_box_connector_Config" doc:name="Mule-box-connector Config" doc:id="7216cd47-6614-4d07-9724-9bbd97bc541d" property_clientId="${box-connector.clientId}" property_clientSecret="${box-connector.clientSecret}" property_host="${box-connector.host}" property_port="${box-connector.port}" property_basePath="${box-connector.basePath}" property_protocol="${box-connector.protocol}" property_localCallbackPath="${box-connector.localCallbackPath}" property_localCallbackConfig="${box-connector.localCallbackConfig}" property_externalCallbackUrl="${box-connector.externalCallbackUrl}" property_localAuthorizationUrl="${box-connector.localAuthorizationUrl}" property_authorizationUrl="${box-connector.authorizationUrl}" property_accessTokenUrl="${box-connector.accessTokenUrl}"/>
</mule>