[Multipart/form-data] Sending a structure as one of the fields

Forge Component
(3)
Published on 2018-12-20 by Kilian Hekhuis
3 votes
Published on 2018-12-20 by Kilian Hekhuis

Hi,

So I need to consume a REST API method that can use form-data. 

I was able to send a request sucessfully with for example a normal parameter and a binary parameter.

The thing is, I would like to send a structure also using this forge component. Is it possible? Im trying to do it and the message binary of the request ( converted to text ) looks like this:



The blue square is the part that Im trying to send as a structure... Is it possible for me to accomplish this? Tell me if you need more info


Cheers

VC

Solution

Hi,

I was able to solve this. I will explain my use case because probably it can apply to someone. I have a REST API method that I must consume which can use both JSON or FORM-DATA as request format and its basically to upload a file. In the API description the properties can be set like this:



But they also say that I can use FORM-DATA to upload the file content. So I used the forge component referred in the topic title and I was able to do upload the file content and the basic parameters like "name" and "nodeType".

From what I thought, the structure of the request If I wanted to send properties should be like the one in the image of my first post. I tried it and wasn't being able to add any of the properties.

So what I tried was to simply add one of the property for example "cm:description" like if it was a simple parameter like this:


And it worked perfectly,

MP if you need any help of this kind

Best wishes

VC

Solution

Hi Vincent,

Great to hear you got it solved. Things like these are pretty API-dependent, so it's always difficult to figure out how to do it.