Is there a way to check if a username is available through the API? I’m thinking about the page, on twitch, on which you can check if a username is available - https://passport.twitch.tv/logins/new.
I don’t see a way to check for that same information through the API.
If not, it’d probably be possible to mimic those same requests that that page makes, right?
You can use the get channels v3 endpoint
https://api.twitch.tv/kraken/channels/CHANNEL_NAME. If you get a channel not found response then the username should be available.
Keep in mind, this is a deprecated endpoint so will be removed at some point in the future, and while there are new endpoints that let you look up a username these are not as reliable for this use case as while they would certainly tell you if a username is in use, it doesn’t differentiate between unused usernames that are available and usernames that are ‘unavailable’ such as deactivated or suspended accounts.
That’d likely just be the equivalent of getting the “time machine” message, though, right? It wouldn’t be as accurate as what you can see on that passport logins page? As far as I understand, that page shows if a username is currently available to be used, right?
Is it worth trying to go through the effort of mimicking the requests on that form, or is there some mechanism there that prevents that? I’m poking at it right now and am getting some “failed to decode JSON” error.
I guess worst case scenario I could load the page up in a headless browser?
The “time machine” page is somewhat like what the newer API endpoints are like in that it doesn’t differentiate between available usernames and ones that are unavailable because of things like suspensions.
The v3 endpoint will give you exactly what you need. If the username is in use, you’ll get back the channel object, if it’s unavailable for some other reason, you’ll get back a 422 unavailable message, and if you get back a 404 not found then the username is available for use.
@Dist thank you so much! Seems to work.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.