How to Upload a File to Box.com

Document created by Rabia_Sozkesen Employee on Jun 13, 2017Last modified by Adam Arrowsmith on Jun 16, 2017
Version 5Show Document
  • View in full screen mode

This article describes how to connect and upload files to Box.com using HTTP Client Connector with OAuth2.0 authentication.

 

 

Use Case

You want to upload an arbitrary file to Box.com.

 

Approach

The approach will use the HTTP Client connector to interact with the Box.com REST API and upload a sample file to Box.com. While doing so we will configure the necessary OAuth 2.0 settings in the same fashion with How to Connect to Box.com with OAuth 2.0 article.  

 

  1. Create HTTP Connection in boomi for box.com upload operation.

  2. Define the file meta data and file content by using message shape.

  3. Format the HTTP request in accordance with box.com API documentation

  4. Execute the process and validate the result

 

Implementation

The following steps detail how to deploy a process using the AtomSphere HTTP Client Connector when connecting to Box.com’s REST API:

 

1) Follow How to Connect to Box.com with OAuth 2.0 in order to create Box.com HTTP connection. Please be aware that upload file for box.com has a different base URL which is https://upload.box.com/api/2.0 . 

 

 

2) Create a sample process that starts with No Data option then add a message shape. Message shape can be utilized to create and define the file description. For example:

 

--simpleboundary
Content-Disposition: form-data; name="metadata"

{1}
--simpleboundary
Content-Disposition: form-data; name="file"; filename="helloWorld.txt"
Content-Type: text/plain

HELLO WORLD
--simpleboundary--

 

Here the file name and parent folder id needs to be passed as a JSON object in metadata section as per Box.com API Upload operation:

 

 

 

 parent id=0 means that the file will be uploaded to the root folder. You should use the folder id as the parent id value if you're trying to upload the document to a specific folder. Folder id can be found in the box.com URL. For example if you open a folder in box.com the URL will look like below: 

https://app.box.com/folder/12345678901 

 

Where "12345678901" is the folder/parent ID. 

 

3) Once the message shape is configured, add a Data Process shape in order to add a carriage return. This step might change or might not be needed depending on your file:

Search/Replace function

Text to Find: [\n] 

Replace With: [\r][\n]

 

4) Configure HTTP Client Connector Operation with below parameters: 

 

Content Type: multipart/form-data; boundary="simpleboundary"

Resource Path: files/content

 

 

A successful attempt would return application status code 201. Because Return HTTP Errors box is checked in the Operation, add a decision shape in order to check the returned Application Status Code document property. Here is how the Decision shape should be configured:

 

First Value: Document Property - Base - Application Status Code

Comparison: Equal To

Second Value: 201

 

Connect these shapes to each other like shown below: 

 

Execute your process. 

 

4) A successful post would result in a JSON response document in below format. The response should contain the new file's id:

{
"total_count": 1,
"entries": [
{
"type": "file",
"id": "185599578603",
"file_version": {
"type": "file_version",
"id": "196694744811",
"sha1": "4b68507f1746b0e5f3efe99b8ef42afef79da017"
},
"sequence_id": "0",
"etag": "0",
"sha1": "4b68507f1746b0e5f3efe99b8ef42afef79da017",
"name": "helloWorld.txt",
"description": "",
"size": 11,
"path_collection": {
"total_count": 1,
"entries": [
{
"type": "folder",

...

 

The complete JSON response can be found here

 

Login to box.com and verify that your file has been uploaded. 

 

1 person found this helpful

Attachments

    Outcomes