Hi,

There is a requirement of consuming an API(POST method) asynchronously. As per my understanding, this is achievable in Outsystem. Please find the below request payloads which I have to send it to the endpoint simultaneously. So, If I send the first request payload, then I should send the second request payload to the API immediately. It means I should not wait for the response for the first request payload. 

Please help me to achieve this.

First request payload: 

  • [{"name":"a"},{"name":"b"}]

Second request payload: 

  • [{"name":"a"},{"name":"b"}]

Third request payload: 

  • [{"name":"e"},{"name":"f"}]


Regards,

Divya

Hey Divya


I had a similar requirement a few years ago

You can create a automatic process that calls your Action, then you just have to call the launch(ProcessName) in your logic


let me know if you need more clarity


Kind Regards

Hi Johann,


Thanks a lot for your response.

I am not aware of the automatic process. But,  I can go through the Outsystem documents. 

Still, I would request you to give some more clarity(OML file) on asynchronous call API. 


Regards,

Divya



 

Step 1 Create a Process with an automatic activity 

Step 2 Create your action that will call the Rest EndPoint

Step 3 Inside you automatic activity Call your action

Step 4 Call the process in inside another method

Ive attached a small demo OML for you to look at

Hi Divya,

HTTP REST calls are, by definition, synchronous. That is, the response follows in the same session as the request. This has nothing to do with OutSystems, this is how web works, technically. Also, in general, REST services typically deliver a response very, very fast. Probably faster than the time it takes to set up a new connection. So sending requests in parallel (which is what you seem to imply, as opposed to "asynchronous", which is something else) might not even be achievable, depending on the speed of the connection and the speed by which the REST service answers.

That said, if you really must do anything in parallel, BPT is the way to go, like Johann explained above.

Hi,


I have tried out that what you have mentioned.

I am calling that process inside screen action. Moreover, I have to send the value(List of text) as an input(request payload) to the API. Inside the process(Automatic activity), I am calling a server action where Consuming_API is called.

The flow is:

Screen action --> Execution of a process instance(Automatic Activity) --> Server action --> API(Consumed)

So, I have to send the request payload(List of text) from screen action to server action. I have used a session variable to store the list of text(Request Payload). But, It did not work. 


Regards,

Divya

Hi All,

Almost I have the same issue(Asynchronous call to an API). I am new to the Asynchronous call. As Johann said, I can use the Automatic process to achieve this asynchronous call. What about the response.

Ex:

Request payload = [1,2,3,4,5,6,7]

I have to segregate the above request payload like below(The threshold value is 3)

  •  [1,2,3]  
  • [4,5,6]  
  •  [7]

First, I have to send the [1,2,3] request payload asynchronously to the API. Then  [4,5,6] and then [7] 

I will get the response back for each request. How can I use that response If I make an asynchronous call? 

Moreover, If any exception occurs during an asynchronous call, How can I handle?

please do help to overcome this.


Thanks

Santhu

Hello Divya,

Processes are asynchronously, for that reason you cannot use the Session Variables or GetUserId() (just like the timers). Probably the best way is to create an input parameter on the process and send the list of texts as text by there. Just delimiter your text with ";" and use the action "String_Split" to get back the List of Texts that you originally have.

In other way you can create a table to store the list of texts and query it inside the action.

Hope it helps, Cheers!

santhu MS wrote:

Hi All,

Almost I have the same issue(Asynchronous call to an API). I am new to the Asynchronous call. As Johann said, I can use the Automatic process to achieve this asynchronous call. What about the response.

Ex:

Request payload = [1,2,3,4,5,6,7]

I have to segregate the above request payload like below(The threshold value is 3)

  •  [1,2,3]  
  • [4,5,6]  
  •  [7]

First, I have to send the [1,2,3] request payload asynchronously to the API. Then  [4,5,6] and then [7] 

I will get the response back for each request. How can I use that response If I make an asynchronous call? 

Moreover, If any exception occurs during an asynchronous call, How can I handle?

please do help to overcome this.


Thanks

Santhu

please, can anyone help me on this...

Regards 

Santhu

Hi Santhu,

Why do you need to send the request asynchronously? What are the response times of the API you are calling? What happens with the replies that are sent back?

Hi Kilian

API will be called by clicking the button in UI, On click of a button I need to form a request as an array, it will contain more than 50 JSON so the consumed API will allow only 10 JSON per array, I have segregated to 10 JSON per array and formed 5 Requests to send to a consumed API.   for each request, response time will be 8 to 10 second.it will slow down the application, For better UI Experience I have to send requests Asynchronously...


Thanks 

Santhu

Hi Santhu,

I understand. In that case, BPT could solve your problem. What I'd do is have a job table (a specific Entity), that holds a record for each request you want to make, and a status (e.g. "ready", "busy" and "done"), and a result. You'd also need another Entity to store the actual data (your arrays) and a reference to the specific job.

Create a BPT process that starts on creation of the job table. Inside there's a single Automatic Activity that reads the job table and associated data, sets the status, connects to the REST API, waits for the result and stores the result (and updates the status again, depending on what kind of statusses you want to have).

Meanwhile, on your screen you need to poll the result of the job table (there's at least one Forge component that allows you to refresh (parts of) the screen), and display it, until everything is finished.

Of course you could even make it more complex, with retries etc., and you'd probably want Light BPT so the calls aren't logged, but BPT is a complex beast, so let's not make it too complex here :).

Hi  Kilian

as per the suggestion from the lead I have to achieve this without creating an entity...


Thanks

Santhu

Hi Santhu,

That's interesting. Could you explain a bit what your final solution is?

santhu MS wrote:

Hi  Kilian

as per the suggestion from the lead I have to achieve this without creating an entity...


Thanks

Santhu


Hi Santhu,

Thing is, you need to store the data *somewhere* until the async process gets around to actually doing its thing.

The only way I see to do this, other than using an entity to temporarily store the data, is to add a input parameter to the process itself.

When you add an input to the process, it gets automatically added as an input parameter of the Launch action, like this:

It also is exposed as a variable inside the AutomaticActivity, which is where you'll call the REST API.