Dynamic REST API method
Application Type


I am trying to create one API which will use dynamic API URLs & Method. However, I am able to change the change the URL of API in OnBeforeRequest callback but when I am trying to change the method from GET to POST, I am getting error as "411 Length Required"

Anyone know how to resolve this?

Hi Shubham,

That usually happens when the request is missing the header "Content-Length". This header is 0 for GETs and DELETEs but you need to specify it for POSTs. That's why you got an error when you changed the method.

Check this link for more details.

I am setting up the Content-Length as well. Still same error!

My suggestion would be to try to consume the API using Postman or even in OutSystems without doing it in a dynamic way and check if it is working. 

If so, your problem must be in the logic you are using to make it dynamic. But with this information it's not easy to check exactly what's going on.

The API is working individually. Below is the screenshot of logic:

Did you try to debug to see if the Content-Length assigned is reached? 
Can you also show us the expression in the if and in the Content-Length assign?

If condition: CustomizedRequest.Headers.Current.Name = "Content-Length"

if True then, CustomizedRequest.Headers.Current.Value = 72

I have also tried debugging. Content-Length value is getting assigned. 

Yeah, I was able to replicate this. I'm not sure if it is possible to change the method dynamically from a GET to a POST just like this because you would also need to change the input/output parameters to fit your new method, and I'm not sure if that is possible.

I'll make a few more tests

If I remove the response structure while changing the method from GET to POST the error wont come up. But this should be dynamic. I wonder if I am assigning the correct value for Content-Length

Hey there, what are you trying to achieve with this? Instead of changing the request type, I would recommend having one of each type, GET, POST, PUT, PATCH etc. as its own action so OutSystems can handle it properly, and only change the URLs

Yes. that can be done but I am trying to build one universal API which can do all of this stuff in order to consume less AOs. That's why I am trying to find out if this is possible 

I would recommend starting with the POST method then downgrading to GET instead of other way around. See if that resolves any issues. This is because GET cannot have bodys so things like the Content Length and Type will be empty and OS probably does not like you modifying those headers.

See if that works. If not, you could possibly also use HTTPRequestHandler or ardoHTTP or even your own custom extension.

When I am changing the methods manually, it is working and no error showing up. I am just trying to find way to do this dynamically.

If it is working fine after changing manually, it should work dynamically as well as we have OnBeforeRequest callback where we can actually change the HTTP method.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.