Consume Rest API multiple POST data

Consume Rest API multiple POST data

  

Hello forum!

I am currently working with an on premises application that connects with a local API and I have some questions about the interface when consuming APIs.

I am using curl to test the API and I hope you will understand what I mean when I am writing examples with curl syntax. For authentication this API uses multiple POST data like so: 

curl POST --data "xxx=xxx" --data "xxx=xxx"

I don't know how to do this in the interface provided by outsystems since writing in the "body"-section is the same as writing --data, how do I create a POST like this?

Sometimes when I am using the API it would be useful to get input variable data gathered from other instances of the application, like a username and password to send for authentication. Is that possible?

Many thanks in advance!

Hi Jack,

I think what you need is to set "Form URL Encoded" as the REST Method's "Request Format", and set your input parameters' Send In to "Body".

Kilian Hekhuis wrote:

Hi Jack,

I think what you need is to set "Form URL Encoded" as the REST Method's "Request Format", and set your input parameters' Send In to "Body".

Oh that might be right! Is there Syntax available for how to set the input parameters to the right value?


Hi Jack,

I'm not sure what you mean. If you use xxx=yyy in curl, you create an Input Parameter called xxx (or something else, in which case you set its "Name in Request" Property to the right name), and assign it the value yyy.

I'm sorry I probably don't know what I'm after either, but my problem is that when I send my POST the server is responding like it sees my first parameter or POST-data but it says that the second input parameter or POST-data is null. I don't know how to assign my second parameter in outsystems to anything with other words. 

Right now I am just pasting the meassage into the "post"-section (with the same names as my input variables I have formed like you nicely described) as a whole like so:

xxx1=yyy1

xxx2=yyy2

where it says that xxx2 can't be assigned to null.

I'm probably missing something..

thanks for your time

Solution

Hi Jack,

I've never come across a REST service that wants form encoded parameters in the body without them being URL encoded. If you select URL encoding, the body of the message will be something like xxx1=yyy1&xxx2=yyy2, I assumed that's what the REST service wanted. But it might be that's not what it wants. Do you have a link to the REST service description somewhere? I'd be interested to know what exactly it needs.

EDIT: it seems curl indeed formats it form URL encoded.

Solution

I didn't use '&', thanks for all your help Kilian :-)

Well, the & shouldn't be needed if you have seperate parameters, OutSystems will (like curl) put them there for you. So for each parameter (in your example xxx1 and xxx2) you need to add an Input Parameter to the REST Method you consume, and OutSystems will do the rest (no pun intended :)). To see what is actually sent, check this post. It may help for trouble shooting (if not now perhaps in the future).