Get notified when there is a changement in a API json

I’ve a twitch bot, and for now, to detect a changement in json of the API, he download them every 5 seconds, and compare with the lasts information… It’s not very optimized, it use a lot of bandwidth and ram (and it’s on a raspberry). I want to know if there is a way to update json only when they change ? My bot uses python.
Thanks for helping me

Depending on what you are watching in API endpoint, you could use PubSub. For now, it’s only for a few functionalities, but i’m sure it will be extended soon.

Otherwise, API calls each X seconds is still the best solution, maybe try to reuse vars and empty memory once object are done being used between two call intervals. I’d suggest you to do a bit more than 5 seconds, as you have to respect your API rates. If it’s only one endpoint that you reach, there is no problem, but as soon as you’ll have multiple endpoints or same endpoint but multiple users or variant attributes inside the endpoint, it will easily reach it.

Have a great day!


Especially if it’s just one request it doesn’t make sense to get it every 5 seconds, since the Twitch API is heavily cached and it (probably depending on the endpoint) can take up to a few minutes for data to update everywhere. I wouldn’t check for new data faster than 30-60s.

1 Like

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