How to get latest events using Helix?

Hi everyone, I’m creating a new app where people will be able to show their latest followers, bits donators, and subscribers in real-time.

For the real-time data, I’m using EventSub, it’s working perfectly and I have no issue with it at all.

My problem is to fetch the initial data when the application is loaded. For that, I’m using the following endpoints:

  • Follower: /users/follows?to_id=USER_ID&first=1 (Working fine for my purposes!)
  • Bits: /bits/leaderboard?period=day&count=1 (I couldn’t test it because my account is not partnered)

The subscribers API is the most problematic one for me because, we have Helix and Kraken (deprecated). However, Helix doesn’t attend to my needs and I think the endpoint is buggy. Why:

Using the endpoint as GET 'https://api.twitch.tv/helix/subscriptions?broadcaster_id=USER_ID':

  1. It returns the default users, but the order that the result comes is totally random, sometimes the first user on the list is not the same.
  2. The cursor is always present, even if I have only a few subscribers or less than the first parameter. The documentation says: If this is empty, you are at the last page. Clearly, I was in the last page and the cursor was still there.

With this issue, I started using the parameter ?first=1, the problem was solved, the result was always the same in this case. But this doesn’t solve my scenario, this is the first subscriber, I need the latest one or the most recent one. Since the endpoint pagination cursor seems buggy, I’m not quite sure what to do.

With this in mind, I started using the Kraken API, I know it’s deprecated but it is what attend my needs, so I’m using it like this: /channels/CHANNEL_ID/subscriptions?limit=1&direction=desc

Because we have the direction parameter available, I can just get the latest subscriber and that’s it.

So based on my problem above, is there a better way to get the most recent events when I load the application? The real-time integration is working fine, my problem is only when I need to show the first data.

Thanks!

this doesn’t return “latest events” it returns the leadboarder.

There’s no “catch up” API for bits/cheer for missed events

Use

https://api.twitch.tv/helix/subscriptions/events?broadcaster_id=ID

It’s a endpoint used for WebSub, but it’s missing from the docs

https://dev.twitch.tv/docs/api/webhooks-reference#topic-subscription-events

covers the documentation for it as a topic, but all websub works as a regular topic. so you want sub/events

HEADS UP, eventsub only returns “new subscribers” not resubs

I think this should be enough for my case… is there a sandbox environment or strategy I can use to test it? Like a test user? Any idea of how I can get the latest bit contributor?

I think I saw another topic mentioning this but it didn’t work as I was expecting… Let me try it again! It always returned an empty string.

Good to know!

Should this be an issue? Is there another way to get resubs? What about Amazon Prime subscribers?

Thank for the quick reply!

No, it’s been requested for many years

Works for me

It only retains data for the last 5 days or so

Regular webhooks has a “better” subscriber notification feed. Or use PubSub

Prime subs are tier 1000, they just paid a different way

Great! I will test it. 5 days must be ok for an active streamer.

My initial implementation was using PubSub but I think it doesn’t support followers, so then for followers, I did a polling system, like fetching the endpoint every minute or so. I wasn’t happy with the solution then I replaced everything with EventSub, regular webhooks was very confusing, especially the part that we need to “refresh” it every 10 days, I use serverless so I don’t have an active server running to put a Cron job there or something. I could add it when the customer logs in but it’s not guaranteed they will log in every 10 days or less.

Is it possible to fetch initial data from Webhook or PubSub? Or they are triggered only there’s a piece of new information?

Also, does EventSub need to be “refreshed” or it will work until it gets revoked?

Webhook/eventsub/pubsub only broadcast when data arrives

Webhook topis are valid helix endpoints so you can call the endpoint

EventSub does not need to be remade

Awesome! I will try to see what I can do about it :slight_smile:

Great to hear!

Thanks for all the quick responses, really appreciate it! I will test it later on then I post here my result.

@BarryCarlyon so it seems some accounts, especially small streamers, don’t have subscriber within 5 days or so, that’s why the endpoint /subscriptions/events might not work for my case :confused:

That’s what I want to do:

image

Real-time data is updating those values, just the initial date is not being that easy to get.

Is it ok to use Kraken? I know it’s deprecated but since I don’t have any plausible solution for my needs using Helix, I might be switch to Kraken, only to get the latest subscriber at least.

I’m wondering how Streamelements can get this data easily. Any clue?

Sure, but it’s gonna die soon.

So if helix doesn’t do what you need, make a feature request on the uservoice

https://twitch.uservoice.com/forums/310213-developers

Personally to “refill” missing data, I’m using webhooks so my database, always has the “last sub” on hand anyway. So I don’t need to backfill like you describe

Oh I see… So you have this data on your own database, so whenever I receive this data from the EventSub, for example, I save it on my own database, then I use this data as initial data.

This got me some ideas, thanks! Maybe I could use Kraken when a new user creates their account, so I;d be using Kraken only once.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.