0

I'm working with an external API (specifically OnlyOffice, if that info can be of any help) using Axios and promises. This particular API works asynchronously, and so returns an object which has to be replenished after the task is finished. My question is, how can I wait for that response to change?

The response has status 200 but with a boolean field that, when I got the request's 200 response, is false. I need to wait till the API replenishes the response with the boolean set as true. How can I wait for that change to happen if when I get a 200 response I already exit the promise with a success through .then()? This is how it looks right now:

await request(data, token)
  .then(response => {
    //response is 200 but with bool : 0
    //I need to wait for a bool : 1
  })
  .catch(error => {});

  • Do you need to keep sending requests? Once you have a resopnse, that's your response. Whatever data it contains is the data you have. Unless the API has some kind of web sockets setup (which their documentation should describe if that's the case) then you'd need to make the request again for new data. – David Jun 30 '20 at 11:31
  • @David I cannot make more requests in this case; the aim here is to copy a file so more requests would generate unnecessary copies. Maybe a way of delaying the promise? Idk – Andrea Casas Jun 30 '20 at 11:38
  • You may need to consult the maintainers of the API for proper use then. You can delay reading the response, but that won't change what the response contains. Once their server responds with data, that's it. That's the data they sent you. – David Jun 30 '20 at 11:39
  • Where does the boolean come into it? It's not referenced in the code except in comments. – Roamer-1888 Jun 30 '20 at 23:54

0 Answers0