Syncing User Subscriptions


#1

Howdy,
I need to update my company’s database with user subscription statuses. I came across this post where it describes fetching all the subscribers of a channel periodically and then updating the database with each subscriber.

Is that still the recommended approach? And is it possible to get all subscribers in one call or do you have to fetch 100 at a time as it mentions in the New Twitch API

Thanks in advance!


#2

Both v5 and New API limit to 100 per page.

So yeah, you have to get it in pages or 100.

But more recently you can use webhooks, so fetch say once per week and then real time handle subs/unsubs using


#3

Thanks Barry!

Just so I’m clear, when that webhook page states:

Blockquote This webhook notifies you when:

  • A payment has been processed for a subscription or unsubscription.

Can I assume that an unsubscription includes the user’s subscription expiring or their account being closed?

Also, are there any best practices or tips for how to efficiently test webhooks for subscription events? We currently have our primary twitch account and a developer account for testing purposes, but haven’t tested for subscription events so I’m curious what is a good approach for that.


#4

Not likely for account closed no. But for expires yes.

If an account dies/closed then it can’t be reusued assumed you are tracking bu userID

The only way to test is to tie up to a real affilated/partnered account and/or just look at the example data in the docs.


#5

Are you able to confirm that the subscriber webhook sample is correct? The user follows webhook has a sample which does not match the actual webhook payload at all (it isn’t an array, to_name and from_name are missing)


#6

The output for the webhook matches the API end point for the same topic.
So if you can call the topic. Thats the same payload you get from the webhook.

So follows matches the output of Helix described here

On the URL/Topic

https://api.twitch.tv/helix/users/follows?to_id=CHANNELID&first=1

{
    "total": 2822,
    "data": [
        {
            "from_id": "SOMNEID",
            "from_name": "SOMENAME",
            "to_id": "SOMEID",
            "to_name": "SOMENAME",
            "followed_at": "2019-08-22T20:09:27Z"
        }
    ],
    "pagination": {
        "cursor": "eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6IjE1NjY1MDQ1Njc0Mjc0Nzg0OTQifX0"
    }
}

The webhook will omit total and pagination. Heres a real one from my log:

{“data”:[{“followed_at”:“2019-08-31T10:04:35Z”,“from_id”:“117945302”,“from_name”:“nenow95”,“to_id”:“26610234”,“to_name”:“CohhCarnage”}]}

This matches the example that is in the Webhook docs

It’s a Object that contains an array of data

Subscribers will match the output of

https://api.twitch.tv/helix/subscriptions/events?broadcaster_id=CHANNELID&first=1

heres a real webhook from my webhook log

image


#7

That’s really strange because that isn’t what I’m getting at all for the follows webhooks :\ I must be doing something wrong if this is what they actually do output for you, will have to go through my requests again to check.

Thanks for the sanity check :slight_smile:


#8

Make sure you are logging the raw incoming post. Rather than something you part parsed


#9

Looks like the problem was that I didn’t send first=1 when requesting the webhook. Tbh I would have expected the request to fail since the docs specify that parameter must be sent, but instead it sent webhooks in a completely different format. The docs are indeed correct for the payload when first=1 is sent.


#10

If this is for the follows end point.

Before first=1 was required for the webhooks, there was a valid topic.
That valid topic is yet to be removed. So you are getting bad/unexpected data from a deprecated topic


closed #11

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