Kindly show some demo, how it work.
i am using Postman to test the API, its has one json and binary file in body content.
Hi Mohan,
I don't have a demo (because that would need a REST service that needs a multipart/form-data, and it's not easily possible to create it in OutSystems). However, these are the steps to take:
In order for your REST API to work properly, you will need to set the right Content-Type in the header. To do so, specify an Input Parameter ContentType, with its "Send In" Property set to "HeadeR" and its "Name in Request" Property set to "Content-Type":
The binary content should be sent in the body ("Send In" set to "Body"), and its data type should of course be "Binary Data".
If you need an example, you can take a look at my ValidSign Component, which uses Multipart/form-data as described above.
Kilian Hekhuis wrote:
Hi Killian,
Good day. I am having trouble using the forge component MultipartFormData. The case is we are trying to recreate a working native API endpoint in Outsystems. We are going to expose an API from OS and there will be a flow where in we will consume that native API endpoint.Here's the thing :
1. It requires a multipart form request. see image below
2. I have tried using parts add for these 5 inputs and then use the SA MultipartFormDataCreate. see image below
But I keep getting this response. See image below
Your advise/help will be highly appreciated. Thank you and have a nice day!
Cheers,
Eruel
Hi Eruel,
The "422" error code typically specifies that the data was received correctly - which would mean that the multi-part/formdata is correct - but that the content itself somehow wasn't correct.
Looking at the Postman input, it seems that target_number, source_number and check_number aren't files, and therefore I don't think you should add them as multi-part/formdata. I'm not entirely sure how you should add them though, whether they should all go in a single part or not. It would be useful to have the exact Postman message, does Postman show the raw input somewhere?
Hi Kilian,
No available raw input on postman. See image below
inputs are only indicated on form-data.
Here's the example of the successful response message.
Can I just put the target_number, source_number and check_number as URL parameters? What do you think?
Thanks!
I don't think that works, as it should be form-data. However, it seems I was wrong, at least partially. I created a Postman request with two text parameters and one file parameter, and sent the request to a REST service in OutSystems, increasing the logging level so I could capture what was sent.
Postman parameters:
Logging in OutSystems:
So it seems that the "name" part should indeed be "target_number" etc.
So it is correct on how I used the PartsAdd functionality? But why does it return a 422 response?
Well, like I said, 422 typically means "Data received ok, but content is not ok". So it might just be you send it stuff it doesn't expect, even though the multi-part/formdata is correct. To troubleshoot this, I'd advise you the following:
Im getting this message on general logs.
Why does it only shows the front_image?
If the log is too long, it cuts it off. You should click the "Download HTTP Trace" to see if that's indeed everything.
If it is, then you might not chain the PartAdds right. You should always use as "Parts" input the "PartsAdded" output of the previous. Debug the code, and verify that the "Parts" input of MultipartFormDataCreate indeed contains all the parts.