[Helix] Clips endpoint not working with 'before' argument (400 invalid cursor)

Hi,

I can see that using before argument with clips endpoint constantly ends with:

{
    "error": "Bad Request",
    "status": 400,
    "message": "invalid cursor"
}

Here is the sample chain for requests I can make to reproduce this issue:

https://api.twitch.tv/helix/clips?first=24&game_id=509658

https://api.twitch.tv/helix/clips?first=24&game_id=509658&after=eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6Ik1qUT0ifX0

https://api.twitch.tv/helix/clips?first=24&game_id=509658&before=eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6Ik5EZz0ifX0

the last cursor was given in the prior request.

This seems like a basic use case.

Can someone explain me what I am doing wrong here?

Regards

Why are you changing from after on your 2nd request, to before on your 3rd? Using before is only for paginating backwards through previous pages of results you’ve already gone past.

You should keep using after and keep replacing the value with the cursor in your last request.

This is exactly what I wanted to do.

Maybe I should clarify this, this is my basic scenario:

  • I call get clips endpoint to get first page of result for specific game_id
  • I use pagination cursor with after argument to get second page of results
  • I use pagination cursor with before argument to get again first page of results

Request made:
RQ1:

https://api.twitch.tv/helix/clips?game_id=509658

RS1:

{
        data: [....],
        pagination: {
              cursor: eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6Ik1qQT0ifX0
        }
}

RQ2:

https://api.twitch.tv/helix/clips?game_id=509658&after=eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6Ik1qQT0ifX0

RS2:

{
        data: [....],
        pagination: {
              cursor: eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6Ik1qQT0ifX0
        }
}

RQ3:

https://api.twitch.tv/helix/clips?game_id=509658&before=eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6Ik1qQT0ifX0

RS3:

{
    "error": "Bad Request",
    "status": 400,
    "message": "invalid cursor"
}

In my undestanding if we have cursor we can navigate backwards and forwards around this cursor. If no, what is the usage of before argument?

Not all endpoints properly support before cursors. I haven’t tested with Get Clips, but it could simply be one of the endpoints that doesn’t allow using before and the documentation could incorrectly list it as a param.

Also, if you want to get pages 1, 2, and 1 again, rather than using before you should just make the request without any cursor and it will give you page 1. Generally for most use cases, such as polling an endpoint, it’s common to just get page 1, keep using after to get as many pages as you need, then the next time you need the data you start from scratch and page through again.

It would be good to add a note in documentation as it is right now a bit confusing. This issue forces to save specific cursors for each page as it is inconvienient if we are on the page number 8 and can’t actually easily go back to page 7.

You shouldn’t be saving cursors and reusing them, otherwise you would get inconsistent results as they’re not designed to permanently represent a place in the results but rather something that’s relevant at the point in time you got the cursor.