Read and write files in Box using Jitterbit Studio
Introduction
The Box connector provides two dedicated file-level activities: Download File for reading files from Box and Upload File for writing files to Box. Both activities exchange file content as Base64-encoded strings. Use Base64Decode to decode downloaded content when processing text, and Base64Encode to encode content before uploading.
Before building the operations described in this guide, configure a Box connection with JWT credentials as described in Box prerequisites.
Design pattern
The pattern uses two independent operation groups.
Reading files from Box
The Search operation locates files in a Box folder and passes the file ID to a project variable. The Download File operation, triggered on the Search operation's success, uses that variable as its File ID input.
Writing files to Box
The transformation supplies the required fileName and fileContent fields to the Upload File activity. fileContent must be a Base64-encoded string.
Part 1: Read a file from Box
Step 1: Configure the Search operation
-
On the design canvas, create a new operation.
-
Add a Box Search activity as the source. Double-click the activity to open its configuration.
-
Name: Enter a name such as
Search Box Files. -
Ancestor Folder IDs: Enter the Box folder ID to search within. The folder ID appears in the URL when viewing a folder in Box (for example, the ID in
https://app.box.com/folder/123456789is123456789). -
Type: Select File.
-
Query: Optionally enter a filename or keyword to narrow results. Leave blank to return all files in the folder.
-
Click Finished.
-
Add a Transformation step as the target of the operation.
-
In the transformation, add a script node at the root level that stores the first matching file's ID in a project variable:
$box_file_id = Source.entries[0].id;Note
The Search response includes an
entriesarray where each item has anidfield. This script selects the first result. To process multiple files, loop through theentriesarray and call the download operation for each ID. -
Save the transformation.
Step 2: Configure the Download File operation
-
On the design canvas, create a second operation.
-
Add a Box Download File activity as the source. Double-click the activity to open its configuration.
-
Name: Enter a name such as
Download Box File. -
File ID: Enter
[box_file_id]to reference the project variable populated by the Search operation. -
Click Finished.
-
Add a Transformation step after the Download File activity. The response schema includes a
fileContentfield containing the downloaded file as a Base64-encoded string. To work with the content as text, decode it in a script node:$fileText = Base64Decode(Source.fileContent);Map
fileTextto the target fields as required by the destination. -
Add a target activity and configure it for the destination.
-
Return to the Search operation. In its operation settings, configure the On Success action to run the Download File operation. This chains the two operations so the download starts only after the file ID has been retrieved.
Part 2: Write a file to Box
Step 1: Configure the Upload File activity
-
On the design canvas, create a new operation.
-
Add a source activity and configure it for the data to upload.
-
Add a Box Upload File activity as the target. Double-click the activity to open its configuration.
-
Name: Enter a name such as
Upload Box File. -
Click Finished.
Step 2: Configure the transformation
-
Add a Transformation step between the source activity and the Upload File activity.
-
The Upload File request schema requires two fields:
-
fileName: Map a string value for the destination filename (for example,"output.csv"). This can be a literal value, a field from the source data, or a project variable. -
fileContent: Map a Base64-encoded string. To encode text content before uploading, use a script node:Base64Encode(HexToBinary(StringToHex($textContent)))Replace
$textContentwith the variable or source field holding the text to upload.Tip
If the source data is already a Base64-encoded string (for example, from a previous Box Download File activity), map
fileContentdirectly without re-encoding.
-
-
Save the transformation.
Verify the integration
-
Deploy and run the Search operation manually.
-
In the operation logs, confirm that the Search activity returns results. If
box_file_idis empty or the search returns no entries, check the Ancestor Folder IDs value and verify the Box connection can access the target folder. -
After the Search operation completes, confirm that the Download File operation runs automatically. In the logs, verify that the download succeeded and that the transformation processed the file content as expected.
-
Deploy and run the write operation. Open Box and confirm the uploaded file appears in the expected location with the correct filename and content.
Tip
To schedule either operation to run automatically, see Schedule an operation to run automatically.