118
Views
9
Comments
How can i get the CustomizedResponse of OnAfterResponse REST API?
Question

I'm trying to display the ResponseText field inside the CustomizedResponse output parameter of the REST API. I wrapped the rest api method inside a server action but there is no option to get the customized response. Thank you in advance for the help.

2025-01-23 09-22-22
ABHIJITH G
Champion

Hi @Rani Kim Tubice ,

As per my understanding If you have the logic to customize the ResponseText field inside the OnAfterResponse, you will be getting the customized response output inside the server action(where you are using the REST API Method), not the one before customizing. So you can directly take the output from the rest API method called inside the server action(which may be in the structure format).

Thanks.

UserImage.jpg
Ice Tube

Hi, 

I'm trying to get the error message from the api and i can't get it from the output from the rest api due to the API call is encountering 404 not found and exception handling does not get the specific message. Here is the screenshot of the api test message i want to retrieve: 

I want to get the message and display in the screen but it is only available in OnAfterResponse.

This is my response body structure:

{  "Result": "string",  

"ErrorMessage": "string",  

"message": "string"}

2019-01-07 16-04-16
Siya
 
MVP

Please change the OnAfterResponse as below where you will check for 404 and raise an exception with the message as the response received from the API.  



2019-01-07 16-04-16
Siya
 
MVP

Alternatively you can capture all the exceptions by changing the condition as Response.StatusCode <> 200

2019-11-11 17-10-24
Manish Jawla
 
MVP

Hi @Rani Kim Tubice ,

Is that possible for you to share the sample oml or screenshot of Onafter response logic you have applied to capture this error message?

I believe if you share the screenshot of logic or sample oml, it will help community member to understand the issue easily.

Regards,

Manish Jawla

UserImage.jpg
Ice Tube

Hi Manish,

I attached a sample OML. The scenario is I'm forcing an error from the API and I want to capture the error and display it in the screen. However, when the error occurs the exception catches only this "500 Internal Server Error" but in the OnAfterResponse > CustomizedResponse.ResponseText output parameter it has the "Endpoint recipe is not running." which is the error message I want to retrieve and display. 

If you open the oml, I have a server action SA_GetAPIResult that captures the response from API that is called from the UI. I can't find the option in the action to get the result from the OnAfterResponse after I call the API method.

I hope this helps. 

TestOML.oml
2019-11-11 17-10-24
Manish Jawla
 
MVP
2022-07-12 01-10-14
Jithu Cheriath Thomas

Hi,

Try to capture the http status in onAfterResponse by using the exception handler and display the message.

If it errors the http status code will not be 200. 

2022-12-30 07-28-09
Navneet Garg

Please check what is the status code in case of error. Ideally it should not be 200 so you can check status but if you are getting 200 then you need to check error message node in json.

Can you please share full response of your api and possible share oml as well.

You need to handle status and exception in OnAfterResponse

https://success.outsystems.com/documentation/11/integration_with_external_systems/rest/consume_rest_apis/simple_customizations/


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