cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Multipart form to API

Ernest_Christia
Level 3
Hello,
We are asked to send a multipart form data to an API using HTTP POST. Should this be done via the Utility HTTP business object under the POST action or should we define this in System under Web API Services?

There are a few requirements:
1. Two static header key and values
2. One variable header key and values (can change per item/transaction)
3. The body is composed of something like:

--form 'metadata="{
"documents": [
{
"documentName": "sample.pdf",
"documentExtension": "pdf",
"documentCategory": "Other Form",
"documentDescription": "Other form uploaded",
"messageId": null,
"documentUploadedBy": "BOT_USER",
"toDisplayText": "ITEM_ID",
"toEmail": "testemail@gmail.com"
}
]
}
"' \
--form 'file=sample.pdf'

^ in the body, aside from supplying the metadata values the file will be uploaded (file=sample.pdf).

I've seen an example in an old post where multipart form data is sent under a template which has [boundary] in the text portion but I couldn't make heads or tails of it, like what is a "boundary" and are everything under [] in a template, parameters? Also are all those parameters required, like the "boundary" mentioned? 

Hoping someone can give a simpler explanation for multipart form sending in Blue Prism.

Thank you,
Chris

------------------------------
Ernest Christian Javier
------------------------------
1 BEST ANSWER

Best Answers

Hi,

It seems to me that the Header collection might have been incorrectly configured. Below is what it should be like.
Also what does Part_Id refer to as per the documentation?

31425.png
31426.png



------------------------------
Shashank Kumar
DX Integrations Partner Consultant
Blue Prism
Singapore
+6581326707
------------------------------

View answer in original post

8 REPLIES 8

GeoffHirst
Staff
Staff
HI Chris,

Thank you for being a SS&C Blue Prism customer and for using Blue Prism.

Multipart, personally I have always found it a bit of a minefield but to try to help. A boundary is that area that separates the parts, hence making it a multipart documents. You should be able to accomplish what you need using the HTTP VBO.

Now, there are quite a few messages on the community boards regarding multipart so my suggestion to you would be to have a search and see what you can find. I usually find every implementation of multipart is different and I have fought with some seemingly crazy implementations over the years.

See how you go and if you are still struggling, come back to us and we will see what else we can do to help.

Once again, thank you for being a SS&C Blue Prism customer.

regards

------------------------------
Geoff Hirst
Senior DX Engineer - Digital Exchange - EMEA
SS&C Blue Prism
------------------------------
Geoff Hirst Senior DX Engineer - Digital Exchange - EMEA SS&C Blue Prism

Thank you, Geoff. Trying the HTTP Utility VBO right now. Not sure if the file is getting uploaded even though I just send as input the FilePath which is in text and not binary or base64.

------------------------------
Ernest Christian Javier
------------------------------

Hi Geoff,

Getting some issue in using the header portion of HTTP Utility.
The response from the server was "Missing API Key Header" despite us including the header collection comprised of the required values:
apikey, name_id and partId  on the corresponding Key and Value columns.

ForcePreAuth and UseBearerToken are both false as well.

Is there another setting we would have to include in order for the headers to be included in the request?

Thank you.

Regards,
Chris

------------------------------
Ernest Christian Javier
------------------------------

@Ernest_Christia,

Can you share some details about the API you're trying to invoke and some screenshots of your action stage configuration and Collection definitions?

Cheers,


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

Hi Eric,
The API is expecting something like this:
HEADER:
--header 'apikey: <ApiKey>'\
--header 'name_id: <NameId>' \
--header 'partId: <PartId>' \

BODY:
--form 'metadata="{
\"documents\": [
{
\"documentName\": \"<DocumentName>\",
\"documentExtension\": \"<DocumentExt>\",
\"documentCategory\": \"<DocumentCat>\",
\"documentDescription\": \"<DocumentDesc>\",
\"messageId\": null,
\"documentUploadedBy\": \"<UploadedBy>\",
\"toDisplayText\": \"<DisplayText>\",
\"toEmail\": \"<EmailTo>\"
}
]
}"' \
--form 'file=@"<FilePathToUpload>"'

(Tried to upload an image of our BP implementation, but the upload does not seem to work so I will describe it instead.)

* We are using the business object Utility HTTP (the new one) and the action used is the Multipart Form.
* Parameters Supplied are:
Address URL
Headers
Force Pre Authorization - False
Use Bearer Token - False
FileMetadata
FieldMetadata

For FileMetadata Collection, the filled out value is the FilePath containing the file to be uploaded's path. Other fields are left blank.
For FieldMetadata Collection, there are two fields, the Name and Value.
Name contains the value "metadata"
Value contains (the items above after the "metadata=" including the brackets but no \ on the double quotes).

So far, the request has been failing in the header validation. Which is odd considering the apikey, name_id and partId are in the "Key" field of the collection, while the "Value" field of the collection contains their corresponding values.


------------------------------
Ernest Christian Javier
------------------------------

Hi,

It seems to me that the Header collection might have been incorrectly configured. Below is what it should be like.
Also what does Part_Id refer to as per the documentation?

31425.png
31426.png



------------------------------
Shashank Kumar
DX Integrations Partner Consultant
Blue Prism
Singapore
+6581326707
------------------------------

Thank you for this. I was able to get through the header validation.

However the new error is that the uploaded file is coming in as an empty file.

Should I enter values in the FileMetadata? I have seen in an old post that someone used application/octet-stream in the  ContentType field. I tried it but still getting the response that the file being sent is an empty file (it isn't, it is a pdf with some content).

Could the error be because we're sending "FilePath" while only "file" is expected in the Body?

------------------------------
Ernest Christian Javier
------------------------------

Hi All,

Was able to finally send the file successfully. It appears that it was necessary to set the Content-Type as application/octet-stream in order for the file to be pushed successfully.

Thanks everyone for your help and suggestions.



------------------------------
Ernest Christian Javier
------------------------------