Now that we’ve seen what the general code expectations of this would be, we can have idea of how to approach this in the connector builder. Using Box as an example, we know that we need to:

  1. Build our form-data object
  2. Build our form-loc object
  3. Build the body of our upload request
  4. Implement the File.Push module correctly
  5. Render this data to our method’s UI

Looking into each one a bit more:

1.Looking at Box’s documentation, we know that we need a single key called “attributes” that is an object containing two items, a “name” field that will be used to save the file inside of their service, and a “parent” object that contains an “id” that tells Box which parent folder to save the file under.

  • To do this, I created an object.construct that looked like so:

    {
    "brick": "object.construct",
    "id": "ATTRIBUTES",
    "inputs": {
    "name": "{{input.File.Name}}",
    "parent": {
    "id": "{{input.File.Parent Folder ID}}"
    }
    },
    "outputs": {
    "output": {
    "_type": "object",
    "_array": false
    }
    }
    }
  • Then I ran it through JSON.Stringify, to stringify that object

  • Then I did a final Object.Construct to build out “attributes” correctly. NOTE I did not need to strictly follow the pattern mentioned above because this “attributes” key does not need headers or params.

    {
    "brick": "object.construct",
    "id": "FORM-DATA",
    "inputs": {
    "attributes": "{{STRINGIFIED ATTRIBUTES.output}}"
    },
    "outputs": {
    "output": {
    "_type": "object",
    "_array": false
    }
    }
    }

2.To build form-loc, Box requires both a “name” field set to “file” and a parameter set to the local file name, which is stringified.

  • I first used JSON.Stringify to stringify the innermost object.
  • Then I used object.construct to build the form-loc’s entire object. NOTE: You must explicitly define your headers. You cannot set it equal to "headers" : {}.

    {
    "brick": "object.construct",
    "id": "FORM-LOC",
    "inputs": {
    "name": "file",
    "params": {
    "filename": "{{STRINGIFIED FILENAME.output}}"
    },
    "headers": {
    "_type": "object",
    "_value": {}
    }
    },
    "outputs": {
    "output": {
    "_type": "object",
    "_array": false
    }
    }
    }

3.Then we must build the body to send as a request to Box. This matches the format defined inside of “General Structure”

{
"brick": "object.construct",
"id": "BODY",
"inputs": {
"url": "https://upload.box.com/api/2.0/files/content",
"protocol": "HTTP",
"method": "POST",
"headers": {
"Authorization": "Bearer {{auth.access_token}}"
},
"form-data": "{{FORM-DATA.output}}",
"form-loc": "{{FORM-LOC.output}}"
},
"outputs": {
"output": {
"_type": "object",
"_array": false
}
}
}

4.Now we need to set up our File.Push module correctly. NOTE 1: input.File.File Content is the ID the user passes in, that represents the ID inside of the platform’s file system (surfaced to them in other cards as “File Content”). NOTE 2: You must add in the body object yourself, because the template is currently broken. There will be a fix for this end of next week, hopefully. This represents the response from the external service about your request.

{
"brick": "file.push",
"id": "REQUEST",
"inputs": {
"id": {
"_type": "string",
"_array": false,
"_value": "{{input.File.File Content}}"
},
"body": {
"_type": "object",
"_array": false,
"_value": "{{BODY.output}}"
},
"query": {
"_type": "object",
"_array": false,
"_value": {}
},
"headers": {
"_type": "object",
"_array": false,
"_value": {}
}
},
"outputs": {
"body": {
"_type": "object",
"_array": false
}
}
}

5.Finally, I did a simple Object.Construct to render my data correctly. Like so:

{
"brick": "object.construct",
"id": "OUTPUT",
"inputs": {
"File": {
"File ID": "{{prevData.body.pathName}}"
}
},
"outputs": {
"output": {
"_type": "object",
"_array": false
}
}
}