https://slingdata.io logo
Hi, I'm testing the pagination in api.
# sling-help
m
Hi, I'm testing the pagination in api. Have some problems, looks like the next_state doesn't increment the value of page (checked with debug and trace). Also, right now the condition is 'state.page >= 2' just for test, and with next_state it enters to infinite loop. But also in stop condition I have a problem. For example, this is the result: { "items": [], "total": { "pages": 1, "items": 180 }, "message": null, "server": { "date": "2025-10-24 08:29:50", "httpCode": 200, "executionTime": 0.043745994567871094 } } So my condition was: stop_condition: 'state.page >= jmespath("response.json", "total.pages") || length(response.records) == 0' But for total.pages it return nil and for length of items no result.. Please assist https://cdn.discordapp.com/attachments/1210406123744796705/1431210887246647356/getlinked.yaml?ex=69047f82&is=69032e02&hm=ce40d4cdff32329facb0472ba209f141fe1d796cae175a64d418234d2cd07026&
f
hey @marikt94 I copy/pasted your spec into VSCode, and right away it showed syntax error. I think there is a indentation error right under
next_state
. Should be
Copy code
pagination:
      next_state:
        # Increment page number
        page: "{state.page + 1}"
      stop_condition: 'state.page >= 2'
Could you try that? I will add some more checks in the spec validation logic to help identify those. https://cdn.discordapp.com/attachments/1431210887452164108/1431228543043375165/image.png?ex=68fca6f3&is=68fb5573&hm=21522a92af470eb7682d03e60a479b288eb209b82e4dd2c80f5a60e9c6e2da0d&
I suggest you install the VSCode [Extension](https://docs.slingdata.io/sling-cli/vscode) if you haven't already
also your stop_condition should not add
"
around
response.json
(that passes it as a string)
Copy code
stop_condition: 'state.page >= jmespath("response.json", "total.pages") || length(response.records) == 0'
should be
Copy code
stop_condition: 'state.page >= jmespath(response.json, "total.pages") || length(response.records) == 0'
m
Hi, thanks for response! Im already installed the extension, but don't sure how it helps me for now.
Also, the double quotes is actually by docs example: "stop_condition: 'state.page >= jmespath("response.json", "total_pages") || length(response.records) == 0'" https://docs.slingdata.io/~/revisions/Rx4OAB9nPXgKZ2vAhZ9A/concepts/api-specs/advanced#common-pagination-patterns I will try the stop condition that you sent. But still, why this pagination mapping doesnt end the run: pagination: next_state: # Increment page number page: "{state.page + 1}" stop_condition: 'state.page >= 2'
May be something with dev release? Because its looks like the dev version is going to infinite loop (I assume). And prod release actually ends
f
> But still, why this pagination mapping doesnt end the run: interesting, are the indent spaces correct? cause the way you pasted, it looks to be the same indent as
next_state
should be like this:
Copy code
pagination:
      next_state:
        # Increment page number
        page: "{state.page + 1}"
      stop_condition: 'state.page >= 2'
m
Oh, I have missed it. But If Im not worng it should be like that, right? pagination: next_state: # Increment page number page: "{state.page + 1}" stop_condition: 'state.page > 2' Like the stop condition should be under pagination and not "next_state"
f
ah you're right, I fixed above
m
BTW, something that happend to me with another API but I can see it now also. By the docs, to do processors on API: records: .... processors: ... but its not working for me (no resut for processors) only if the processors with indent space under records like that: records: processors:
f
thanks will fix
m
there is something that corelates to pagination issue, so I will send it here.. I want to add the page_id to result in final table. so this is the response: response: records: jmespath: "items[]" # limit: 10 processors: - expression: 'state.page' output: "record.page_id" The request with given filters provide 100 records per page, and there is only 2 pages for now. But the page_id result behaves chaotic.. One time I see for all rows value of '3', another run ther is only '2', and one time they mixed, but no value '1'
f
ah ok, I think I know why, the state can be updated (by
next_state
) before the processors are processed. Will take a look and let you know
m
Just to make sure, Im running prod version of sling, because dev is stuck when running with pagination
I tried with latest dev version
f
what do you mean stuck?
m
after running command, no log (looks like enter inifine loop)
not proceed from that point
f
can you run with
--debug
?
can share log?
Im also dont understand why it goes to page 3.. I have identical request in postman, and there is only 2 pages for this request
f
@marikt94 OK can you try with latest dev build? fixed a few issues, but I was unable to reproduce the pagination freeze.
I use spec:
Copy code
name: "Example API"

defaults:
  state:
    base_url: https://swapi.dev/api
    now: '{ date_format(now(), "%s") }'

  request:
    headers:
      Accept: "application/json"

endpoints:
  data_planets:
    state:
      id: 1
      
    request:
      headers:
        KEY1: '{secrets.my_key}'
      url: '{state.base_url}/planets/{state.id}'
      method: GET
      parameters:
        limit: 2
        key: '{secrets.my_key}'
      
    pagination:
      next_state:
        id: '{ state.id + 1 }'
      stop_condition: 'state.id >= 4'
./sling run --src-conn swapi --src-stream data_planets --stdout --debug
m
Looks like no freeze anymore. thanks!
@flarco Hi. Im again into freezeing issue. If log states that we already get response, than it is not the issue of timeout or waiting from the server, right? Anyway, I would glad to get you help to see if its not the sling issue. because I can see, that one time it can proceed very fast, and another run it can stuck
BTW, it is not big amount of data.. 2 pages of 1000 rows..
We already have a process very similar to that when in loop we taking data from that and other api's with pagination..
BTW, I defined timeout to 60.. if its seconds, it means that process should already be failed but it still in process
I also tried another api source, and there is also some freezing issue
f
OK, thanks, so it is not deterministic, correct? like, it works most times and then freezes some times, correct?
m
Right now in most cases its freeze and sometimes it works..
I will try to run the process 10 times and I will let you know shortly the ratio of freezes
f
can you run with
--trace
and make it freeze and share that log?
m
Yep
2 first runs were fine, but this one is stuck.. And my expectations that process will fail\stop if its no answer from server due the timeout
BTW, I try to run it several times.. only after third run it succeed without freezing
f
ok @marikt94 can you try with latest dev build when you get a chance? If it's still happening, can you run with
--trace
and share output again? thank
m
Ok, looks good.. have did 10+ runs and it was smooth. I will try tomorrow more to make sure. Thanks alot!