127
Views
5
Comments
problem Quick API Response with Empty Results: How to Ensure Proper Data Retrieve
Question
Application Type
Reactive

Hi Everyone,


I have a problem with consuming the REST API. It returns very fast. For example, when I call the API, it usually takes up to 6 seconds from the endpoint to query and return the value. However, it only waits for 2 to 3 seconds and then finishes the API call, resulting in an empty response.

It seems like it is not waiting for the data query to finish from the other side before returning. I know there is a timeout setting, usually defaulting to 10 seconds. Even when I increased it to 60 seconds, I still face the same problem. The API call completes after a short while, without waiting for the actual result. Consequently, most of the time, I receive an empty response. It only works if the result can be returned very quickly.

I wonder if I am missing something? Can anyone help me with this? How can I make the API call wait until the actual result is returned before finishing the call?


Thank you


regards,

Ryan

UserImage.jpg
vikas sharma
Champion

Hi Ryan,

If you can more information about request response then it will be more helpful, also what you are expecting in the response. May be API are designed in a way that it doesn't return any value.

But if you have doubt as getting nothing in response. Then check response headers what is value of HTTP Status code there. On the basis of status code we can identify the possible reason of failure.  So there may be many possible reasons behind the scene like invalid URL, authentication missing, invalid request or may be some kind of restriction on IP or network. So http response header is only thing from where you can get clue.

If you are facing problem in OS application only then also would suggest try in Postman also. Check there structure your request and once get success there then implement same in OS later

regards.

UserImage.jpg
JING TUNG WONG

Hi Vikas,


I have tested the URL using POSTMAN, and there is no problem as the return status is 200. However, the return value is empty. In POSTMAN, when I test the URL, it takes around 5 seconds to load the data, and I can see the value. But when I call the API from the (OS), it seems like it doesn't wait for the data to come from the query. The OS simply calls the API and returns within 1 or 2 seconds, which is why it never receives the data. The issue is that the OS doesn't wait for the data to arrive before returning. How can I make the OS wait for the data to be retrieved before it comes back? 


Thank you


Regards,

Ryan



UserImage.jpg
Alexandre Yip

Hi Jing,

Add to your REST 

OnBeforeRequest

OnAfterResponse

callback actions and log or debug to find out why the result is empty 

Check out here how to customise 

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


Hope that it helps you 

UserImage.jpg
JING TUNG WONG

Hi Alexandre,

I have already checked the logs, and there are no errors. The API is returning a status of 200, indicating a successful request. However, the issue is that the API is not waiting for the query result. Instead, it quickly returns without waiting for the data from the API, which results in an empty response. As a result, I always receive an empty response from the API. 


Thank you


Regards,

Ryan



2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @JING TUNG WONG ,

testing some api with Postman tells you nothing about what will happen from your Outsystems integration, as there could be all kinds of reasons why your actual call is different.  You need to investigate further into that to know what is going on.

I think you assumption of Outsystems 'not waiting' is unlikely, it could run into a timeout, but will then raise the appropriate exception.

It is much more likely that there is a (small) difference between how you invoke it through Postman and how you invoke it through Outsystems integration.

I think step 1 would be to invoke it from the API test functionality within Service Studio.  Can you tell us what happens when you do that ?

Dorine

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