Querying videos with cursor results in "Invalid value for offset: 600"


#1

I’m running into an issue on the videos endpoint where the helix API gives me a cursor to query more data but barks at me if I try:

GET /helix/videos?first=100&type=archive&language=en&period=month&game_id=499003&sort=trending
> {'pagination': {'cursor': 'eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MTAwfX0'}, 'data': [100]}
GET /helix/videos?first=100&type=archive&language=en&period=month&game_id=499003&after=eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MTAwfX0&sort=trending
> {'pagination': {'cursor': 'eyJiIjp7Ik9mZnNldCI6MH0sImEiOnsiT2Zmc2V0IjoyMDB9fQ'}, 'data': [100]}
GET /helix/videos?first=100&type=archive&language=en&period=month&game_id=499003&after=eyJiIjp7Ik9mZnNldCI6MH0sImEiOnsiT2Zmc2V0IjoyMDB9fQ&sort=trending
> {'pagination': {'cursor': 'eyJiIjp7Ik9mZnNldCI6MTAwfSwiYSI6eyJPZmZzZXQiOjMwMH19'}, 'data': [100]}
GET /helix/videos?first=100&type=archive&language=en&period=month&game_id=499003&after=eyJiIjp7Ik9mZnNldCI6MTAwfSwiYSI6eyJPZmZzZXQiOjMwMH19&sort=trending
> {'pagination': {'cursor': 'eyJiIjp7Ik9mZnNldCI6MjAwfSwiYSI6eyJPZmZzZXQiOjQwMH19'}, 'data': [100]}
GET /helix/videos?first=100&type=archive&language=en&period=month&game_id=499003&after=eyJiIjp7Ik9mZnNldCI6MjAwfSwiYSI6eyJPZmZzZXQiOjQwMH19&sort=trending
> {'pagination': {'cursor': 'eyJiIjp7Ik9mZnNldCI6MzAwfSwiYSI6eyJPZmZzZXQiOjUwMH19'}, 'data': [100]}
GET /helix/videos?first=100&type=archive&language=en&period=month&game_id=499003&after=eyJiIjp7Ik9mZnNldCI6MzAwfSwiYSI6eyJPZmZzZXQiOjUwMH19&sort=trending
> {'pagination': {'cursor': 'eyJiIjp7Ik9mZnNldCI6NDAwfSwiYSI6eyJPZmZzZXQiOjYwMH19'}, 'data': [100]}
GET /helix/videos?first=100&type=archive&language=en&period=month&game_id=499003&after=eyJiIjp7Ik9mZnNldCI6NDAwfSwiYSI6eyJPZmZzZXQiOjYwMH19&sort=trending
> {'error': 'Bad Request', 'status': 400, 'message': '{"error":"Invalid value for offset: 600","message":"Invalid value for offset: 600","status":400}'}, arguments were: {'params': {'first': 100, 'type': 'archive', 'language': 'en', 'period': 'month', 'game_id': '499003', 'after': 'eyJiIjp7Ik9mZnNldCI6NDAwfSwiYSI6eyJPZmZzZXQiOjYwMH19', 'sort': 'trending'}}

The “Invalid value for offset: 600” could be explained if the “cursor” would just be an encoded offset, because the error occured on the 7th call, which would have been offset 600. All the results contained 100 results, which indicates there being more results to query.

My current workaround would be to just not query that much data, since I don’t really need that much, and just assume the cursor is over if it starts giving me these weird errors.


#2

The “Invalid value for offset: 600” could be explained if the “cursor” would just be an encoded offset

Yeah, it’s just base64… The cursors in the above example are as follows:

{"b":null,"a":{"Offset":100}}
{"b":{"Offset":0},"a":{"Offset":200}}
{"b":{"Offset":100},"a":{"Offset":300}}
{"b":{"Offset":200},"a":{"Offset":400}}
{"b":{"Offset":300},"a":{"Offset":500}}
{"b":{"Offset":400},"a":{"Offset":600}}

#3

Yeah, I ran into this issue a while back and it was never addressed. This is the only endpoint that has this behavior, which is even more weird.