cancel
Showing results for 
Search instead for 
Did you mean: 

BOX API Upload

matthew.cable
Level 5

Hi 

Please can I have some assistance with regards to uploading a document to Box via an API.

Currently our API's go through Mulesoft, I have managed to create API's in Blue Prism to Search, Delete Folder, Delete File, Get folders etc... However I can get the Document Upload request to work.
This is working in Postman, but I am unsure how to move this into Blue Prism. We are using Basic Access which works fine.

I have done all of it so far via Web API Services and would like to keep the upload in that part also

I have attached a file with what postman looks like and from BOX what they require.

Thank you



------------------------------
Matthew Cable
Consultant
Zurich
Europe/London
------------------------------
39 REPLIES 39

ewilson
Staff
Staff
Hello @Matthew Coleman,

From the looks of it, you need to perform a multipart form upload of the document with some JSON added to the body. You can do that with the Web API Services feature, but it will require you to use the Template option for the body content. You will then need to define the body template.​ There are a few discussions on the community about this sort of thing. I've linked one below.

https://community.blueprism.com/discussion/error-while-upload-a-file-with-api-using-multipart-form-data#bm79e4317e-9b6e-4bac-a806-f84963a5c657 

Cheers,

------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hi @ewilson

Thank you very much for the quick response, I have attempted what the others ones mentioned but this has not worked.

I am getting a 415 error, i have tried with and without a binary file.

Please can you assist further, I have added screenshots below of the API

22330.png22331.png

Thank you 
Matt

------------------------------
Matthew Cable
Consultant
Zurich
Europe/London
------------------------------

@Matthew Cable,

I would try something like this:

--[boundary]
Content-Type: application/json; charset=UTF-8

{
  "name": "[fileName]",
  "parent": {
    "id": "[id]"
  }
}

--[boundary]
Content-Disposition: form-data; name="[fileName]"
Content-Type: [mimeType]
Content-Transfer-Encoding: base64

[fileValue]
--[boundary]--​

When performing a multi-part your binary file contents should be at the end of the request followed by only a --[YOUR BOUNDRY]--. Also, the Content-Type header should be set to whatever the mime type of the file is. For example, if it's a PDF you should set the Content-Type to application/pdf.

Parameters Above:
  • boundary
    • Type: Text
    • Ex Value: ----------xyz
  • fileName
    • Type: Text
    • Ex Value: MattTestFile2.txt
  • mimeType
    • Type: Text
    • Ex Value: text/plain
  • fileValue
    • Type: Binary
    • Ex Value: Binary contents of a file.

Cheers,

------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hi @ewilson,

Thank you for the above, I am still receiving a 415 error message​.

Below is how I have entered it.

22338.png
My parameters have been

fileName = "MattTestFile2.txt"
Folderid = "Example 123456"
mimeType = "text/plain"
Binary = Example, the binary path.

Below is the error.

22339.png
Any more help you can provide would be greatly appreciated.

Thank you

------------------------------
Matthew Cable
Consultant
Zurich
Europe/London
------------------------------

@Matthew Cable,

​My recommendation would be to test this from Postman one more time, but after you do take a look at the raw message in the Postman Console to see exactly how Postman set it up. It should include all the header and form information. Then it's just a matter of recreating that in the Web API definition.

Here's an example:
22342.pngYou might have to click on the Show raw log option in the top right corner of the Console display.

Cheers,


------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hi @ewilson 

Thank you for the assistance, we are still struggling at this side to work it.
Are there any other suggestions? we are getting a 400 error. 

Postman it works fine but duplicating in Blue Prism is still an issue.

Thank you



------------------------------
Matthew Cable
Consultant
Zurich
Europe/London
------------------------------

Hi @Matthew Cable

  • Can you share screenshots of the Postman raw log information and your current template definition? 
  • What are you setting the Content-Type value to?
  • Are you passing in a binary file? If so, have you tried setting Content-Type to application/octet-stream?

Cheers, 



------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hi @ewilson 

Below is screen shot from Postman raw data being input
22357.png
Below is what I am using, on difference is the ID folder location i am saving to, I decided to just hardcode most of it for now into the template until i can find out what is wrong.

22358.png
Below is the error message I am seeing

22359.png

Here is a link to the BOX developer portal on how to upload a document

https://developer.box.com/reference/post-files-content/

I have amended the content type but i now get a 415 error

22360.png



------------------------------
Matthew Cable
Consultant
Zurich
Europe/London
------------------------------

@Matthew Cable

One quick question. The lines I highlighted below are actually on one single line within your template definition, correct? So the actual Content-Disposition entry looks like this: Content-Disposition: form-data; name="attributes"; Just making sure because you do not want these particular items to have line breaks.

22366.png

Cheers,



------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------