Forum Discussion

jhagist's avatar
jhagist
New Contributor III
7 years ago
Solved

Rest API Test For Completion

I have a pattern where I run a REST POST api call and then need to run a REST GET to see if the request has completed. I need to somehow loop back to run the REST GET again if it isn’t done.

Recommendations on how to handle this pattern?

  • Incredible. It was right in front of me all along. 😎

    So here are the pictures.

    This is the API response. (in this case I need status = success. It tells me I can go get the data)

    This is how I set up the Rest GET Snap. I have Has next set to try again if status <> success.

    Hopefully this won’t be as painful for you as it was for me!!

12 Replies

  • Use Union Snap before REST GET which will have 2 inputs and after GET Place Script and a router(If required. To go futher or loop back) and route back to REST Get Via Union Snap.

  • jhagist's avatar
    jhagist
    New Contributor III

    Incredible. It was right in front of me all along. 😎

    So here are the pictures.

    This is the API response. (in this case I need status = success. It tells me I can go get the data)

    This is how I set up the Rest GET Snap. I have Has next set to try again if status <> success.

    Hopefully this won’t be as painful for you as it was for me!!

    • mbostrom_dtiq's avatar
      mbostrom_dtiq
      New Contributor II

      hi i’m wondering why your solution isnt working for me. same use case. but i am seeing it not waiting until there is a success as in this example:

      Then the next step still shows the job status = “queued”

  • jhagist's avatar
    jhagist
    New Contributor III

    Ok… I am a bit confused. So I need to follow this pattern.

    Rest Post request data
    Rest Get to see if it has completed.

    So in the scenario that the Rest Get returns it isn’t done, I run my wait script (Python) but how to I run to the GET again?

    Thanks for you response!

  • jhagist's avatar
    jhagist
    New Contributor III

    ok this is weird. When I put it in my pipeline I am getting this error message.

    Pipeline failed to prepare

    Reason: java.lang.StackOverflowError

    Resolution: Please address the reported error

    The snap it is failing on is not in the loop section at all. It is the directory browser.

    Has anyone seen this and what is the fix. Also if I break the router and union connection. It works.

    • christwr's avatar
      christwr
      Contributor III

      I had that error too…

      I was intrigued by the looping logic mentioned in the thread above because I had never seen or thought about doing something like that. But when I put together a simple pipeline to try and test it out (see below) I get the same StackOverflowError when trying to run or validate the pipeline.

      As far as the snap it is failing on, I think it just mentions the first snap, but really failed trying to prepare the pipeline, not necessarily with the first snap…

      • cstewart's avatar
        cstewart
        Former Employee

        The way to address this one is to use the REST GET Snap, and use the HAS NEXT functionality. You can make it iterate until the correct response is received.
        (You may not have a loop in a pipeline)

  • christwr's avatar
    christwr
    Contributor III

    So aside from the REST GET snap that happens to have it’s own built-in next/loop within the snap itself, is there a recommended pattern for achieving a “while” type of loop within a pipeline? That’s the piece I was excited about from some of the examples when this thread started off, and sounded like more than one person somehow had it working. Interested in people’s tricks.

  • jhagist's avatar
    jhagist
    New Contributor III

    Not sure that this is what you are looking for but it looks promising.

    Retry Snap

    Wondering if anyone has used this? What was your use case?