TWITCH API: I'm getting an undefined variable but I can't figure out why!

This project has taken me almost a month. The API threw a wrench in the gears and made it incredibly difficult to on the search part of “read” “search” “ask”, so now I’m on ask. I’ve got this at like 90% for functionality, but it’s getting stuck now on an undefined variable and I at the end of my rope with it.

I can’t get the variable to define for the last for loop needed to check deleted users. I’ve checked it and checked it and checked it, but I can’t find the problem. If I set up my AJAX call to use the client ID, it returns “null” no matter what I enter. If I remove the client ID, I get the correct “error” response, but then the undefined variable keeps me from doing anything with it.

I’m stuck. Can someone look at this and tell maybe give me a hint?

I think you are over complicating it a little bit. Instead of having ajax calls based on the users, why not have an array of users that you pass into a function that makes the ajax calls? for example:

var users = [user1,user2,user3,user4];

You then write a function that takes in a user as param and uses that for the url for both the users call and the streams call. When you get a response from the /users/ call you check if it’s a non existent user or an invalid user (for ex data.status === 404), you can then set the user to invalid and/or n/a. If not you can move to the streams. If the stream is null , then user is offline (remember this same user passed the test of whether or not it was a 404).

Just an idea, hope it helps

Thanks for the advice. I didn’t want to use the user array because I wanted a dynamic list, rather than a static hard coded one.

The trouble now is I can’t get an API response to give me an error for non-existent users as long as I’m using a Client ID. But, for some reason, my variable “deleted” is not registering and it’s logging ‘undefined’ to the console every time.

How do you retrieve the Client ID you are planning on using for the API call ? why not make a call to users/someUser and the response will be either code 422 or 404 (deleted/closed account or non existent) and then take it from there?

But shouldn’t this method work? I accept there is probably a better way to do it, but I’d really like to understand why what I have here isn’t working.

It seems like it’s some rudimentary JavaScript error, but I can’t find it.