111
Views
6
Comments
Rest API Post consume - return no values
Question

Hello, 

I am trying to consume my own rest api which is a post method and consists in sending a raw text file (follows a json format) and returning the content which could be a plain text format by the moment. 

The problem is that I am getting an empty content, even after testing it in outsystems as you can see in the images. How could I do it?? 


This is the test:

In the "OnAfterResponse" method I do have the reply content:

However whenever I receive the response there is nothing at all: 



Hello,

Create a "new struct" using the response in response.text on "onafterresponse" and assign the new struct to your output response.

I believe there are some problem in your actual structure.

Hi @Fábio Vaz

If I have implemented correctly what you have said, the reply is still empty:

Now I have a response text in my method. 


Within the "OnAfterResponse" I see the return message as per the image below. Therefore, within the event, the return message is there. 

I have tried to assign this content to whether the CustomizedResponse or the Response itself, but, when trying to recover the API method return, is still empty. 

Empty:

Hi Felipe,

The only way I can see this happening is that you have an attribute name not matching the attribute in the JSON, or the "name in JSON" property is set to a wrong value, in which case the parsing goes wrong (which is done after the "On After Response" is called). Can you share a module?

Helloe @Kilian Hekhuis, @Fábio Vaz . 

I found the issue and fixed it, besides the fact that I don't understand why it did not work. 

Solution: I have created a client action which calls my rest API. Therefore, when calling it from the interface, it works. By some reason, when calling the rest API whether directly from the interface or via a Server Actions, it did not preserve the return when it came back to the interface. 

That's really weird, and I have no idea why it is what you experience, but I'm glad you found a workaround.

hey @Felipe Cabral Jerônimo  and in my case I figure out is some optimization made automatically by the platform, because I was just debugging but I was not using any attribute from the output structure.

It happens in the same way if I put the call through a server action, I can see the output as expected when debugging in the server but the output variable comes empty in the client debugger. 

When I use the output in the screen, for instance, it works. Also, if I wrap the call in a Client Action from the Logic Tab (not "screen action"),  it returns the expected output as you've mentioned - probably because the output is not optimized, since the platform doesn't know where it can be used and has to return the complete output?

Anyway, just wanted to share this here since others can pass through the same issue.

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