Forum Discussion

terrible_towel's avatar
terrible_towel
New Contributor II
2 years ago
Solved

How do I loop through pages with JIRA API, using the HTTP Client snap?

Hi,

I've been trying to configure the snap with no success.

My goal is to do a get request, and loop through the pages, since Jira API only returns the first page.
So it would look something like this:
http://jira_get_request & offset = X 

The offset keyword is concatenated at the end of the request, where X is the page number.

Can anyone here help me configure this using the HTTP Client snap?

Thanks !

  • terrible_towel - If you have specified any of the query parameters in your original URI, I suggest you move them to the Query Parameters settings.  This will make the pagination configuration simpler.

    Has Next: $entity.issues.length == $entity.maxResults

    In the Pagination section, set as below:

    Hope this helps!

5 Replies

  • terrible_towel - If you have specified any of the query parameters in your original URI, I suggest you move them to the Query Parameters settings.  This will make the pagination configuration simpler.

    Has Next: $entity.issues.length == $entity.maxResults

    In the Pagination section, set as below:

    Hope this helps!

    • terrible_towel's avatar
      terrible_towel
      New Contributor II

      Thank you koryknick !

      Your suggestion worked. I'm a bit confused since I was able to get what I want using a different approach - using the NEXT URI property. Is one approach better than the other?

       

  • terrible_towel - I'm not familiar with the JIRA API response, but if you can capture and share the output of the first response, I can help you create the Has Next and other pagination properties.  Feel free to remove the actual ticket data - I just need to see the rest of the response metadata.

    • terrible_towel's avatar
      terrible_towel
      New Contributor II

      Thank you koryknick  !

      Take a look at the screenshot below please. From my understanding of the Jira API, there are 3 relevant properties here: 'startAt', 'maxResults' and 'total'. The new URI (the second and onwards) is supposed to make the same get request, but with an added suffix:

      base_URI  & startAt = ('startAt' + 'maxResults').

      This way it's pretty easy to loop through the pages by incrementing this expression by 50 each time. Then there's the stop condition. I'm guessing something like:

      when 'total' <= ('startAt' + 'maxResults')

      My issue is as I've mentioned, how do i configure these expressions inside of this HTTP Client snap? how do I incorporate this arithmetic behavior? Thanks!

       

       

  • terrible_towel - sorry for the delayed reply.  Coding is both science and art, and much like sculpture and paintings, "better" is often a subjective term.  There is no real performance difference in your solution vs mine. 

    Personally, I try to take a minimalistic approach, which in this case means overriding just the one query parameter that changes rather than reconstructing the entire URI in the Next URI property.