REST GET API with Body Input Parameter

Hello,

I am trying to consume an REST API, this API is a GET Method and I am sending a parameter via URL, (Ex. https://domain/api/APIName?id={id}) but I need to send another parameter as request via Body, as the example below:

{
"name":"Claudia",
"lastname":"Maldonado",
"zip":"12345"
}


But when I set the input parameter I get the following error:

"Input parameters with Send In property set to 'Body' are not allowed for GET methods. Either change the 'APIName' method, or remove the input parameter"


Is there a way for me to complete the configuration for the API to allow me to set the input parameter as Body in a GET method API?.



Hi Claudia.

You can set each parameter individually to be URL, Header or Body. Can you change the Send In and try again?


Hi Nuno Reis,


Yes, I did change the Send In as Body.



But when I do that I get the error because the API is a GET method.

Is not possible for OutSystems to configure this type of variables when the API is a GET method? Do I need to change the API?


Best Regards,

Claudia Maldonado.

I'm consuming Cloudflare API with a REST webservice.

I use the required header inputs and added a few URL. it works.


Claudia Maldonado wrote:

Hello,

I am trying to consume an REST API, this API is a GET Method and I am sending a parameter via URL, (Ex. https://domain/api/APIName?id={id}) but I need to send another parameter as request via Body, as the example below:

{
"name":"Claudia",
"lastname":"Maldonado",
"zip":"12345"
}


But when I set the input parameter I get the following error:

"Input parameters with Send In property set to 'Body' are not allowed for GET methods. Either change the 'APIName' method, or remove the input parameter"


Is there a way for me to complete the configuration for the API to allow me to set the input parameter as Body in a GET method API?.




Hello Claudia,

A GET API method should never contain a request Body, "The GET requests cannot have a message body. But you still can send data to the server using the URL parameters. In this case, you are limited to the maximum size of the URL, which is about 2000 characters (depends on the browser)."

You can also check the following spec book HTTP/1.1 spec, section 9.3


Best Regards,

Francisco Freire

I don't know if webservices do something with them or if they can expect two types, but I successfully tested this API (REST, GET) with the required Header parameters and some unrequested URL parameters.

That error shouldn't show.

Hi Claudia,

In general theory of HTTP methods, the GET cannot include the body when sending request. If you try to attach it, in some server handler, they just ignore it. Following this rule for GET method, OutSystems prevents you to make the same mistake again, I think it is better than letting you attaching body and nothing works.

By your case, I think URL and header are enough

Hope this help!

Thanks for that input Shingo.

So, if the implementations can be different, the specification that Claudia has could be trying to mix both (as in authentication on body, filters on URL).?

This made me curious because I successfully tested with URL, Header and Body parameters so Service Studio is not checking that.


Nuno Reis wrote:

Thanks for that input Shingo.

So, if the implementations can be different, the specification that Claudia has could be trying to mix both (as in authentication on body, filters on URL).?

This made me curious because I successfully tested with URL, Header and Body parameters so Service Studio is not checking that.


Maybe some bugs with Service Studio version you are using at that time. I guess you cannot do it with the latest version.

In my opinion, the main things for specifying input params by URI for GET method are caching and proxying which can improve the performance significantly. Therefore, body in GET request is not a good idea