How to set "sleep" time between Service Callouts

I have two requests to an external service that are being made by the Service Callout policy, after the first is done I grab its result and send it to the second one.

The problem is, I have to wait around 1 second so the backend can process the first request before I make the second, since the resource is asynchronous. How could I make Apigee wait 1 second between both requests?

I tried creating a JS Policy with "setTimeout" but Apigee returns " Javascript runtime error: ReferenceError: setTimeout is not defined".

Solved Solved
0 2 171
1 ACCEPTED SOLUTION

Thanks for the reply, we just have access to Apigee Edge so no Application Integration.

I was able to make it work using a "sleep" implementation in Javascript based on Date.getTime() and a while loop instead of setTimeout.

View solution in original post

2 REPLIES 2

I don't think of Apigee  as a good system for doing this kind of integration. Apigee is best an API proxy, a reverse proxy, which means it validates requests it receives, and then sends them to a backend system.  There's no built-in feature in Apigee to "wait a little while" for some upstream system to get ready.  You can use an integration system like Application Integration, to accomplish that task, as well as many others. 

If you REALLY DO just want to wait a little while, there's a Java callout that does that. 

 

Thanks for the reply, we just have access to Apigee Edge so no Application Integration.

I was able to make it work using a "sleep" implementation in Javascript based on Date.getTime() and a while loop instead of setTimeout.