Error with XMLHttpRequest() to club member API - Help appreciated

Sort:
VirtualKnightJoakim

Just a few days ago below worked:

var request = new XMLHttpRequest();
request.open('GET','https://api.chess.com/pub/club/thailand/members',false);
request.send();

Now I get an error:

As you can gather, I execute the script directly from the Chrome consule.

Any advice?

Martin_Stahl

That endpoint works well by putting it in an address bar.

VirtualKnightJoakim

Yes, https://api.chess.com/pub/club/thailand/members resolves.

A few days ago the below syntax worked for me:

var request = new XMLHttpRequest();
request.open('GET','https://api.chess.com/pub/club/thailand/members',false);
request.send();

Not sure what happened. What I want to do something like below, but now I get an error early in the script:

var request = new XMLHttpRequest();
request.open('GET','https://api.chess.com/pub/club/thailand/members',false);
request.send();
var response = JSON.parse(request.responseText);
response= response.weekly;
var list = '';
var d = new Date();
for(member of response){if (new Date(+member.joined*1000) < new Date('Sun Aug 14 2021 09:50:43 GMT-0400')) list += '@' + member.username + ', ' + '\r\n'};
console.log(list);

If anyone could share a script snippet that works, it would be much appreciated!

Martin_Stahl

I did a quick test via another method and that seemed to work fine as well. Unfortunately I'm not an expert so can't say what might be the problem on your attempt.

 

I mostly dabble with the API and have done most of my testing with PowerShell.

I know this works: Invoke-RestMethod -Uri "https://api.chess.com/pub/club/thailand/members" -Method GET

 

VirtualKnightJoakim

Could you possibly provide a snippet for an alternative syntax for:

var request = new XMLHttpRequest();
request.open('GET','https://api.chess.com/pub/club/thailand/members',false);
request.send();

var response = JSON.parse(request.responseText);

Martin_Stahl

Try removing the false section. I think that will work for you; that will cause the call to be asynchronous 

Martin_Stahl

If that works the site may have changed some things to reduce load and may not support synchronous queries on some endpoints.

VirtualKnightJoakim

Below did not work either for me:

var request = new XMLHttpRequest();
request.open('GET','https://api.chess.com/pub/club/thailand/members');
request.send();

It gives 1 error (with "false" 2 errors).

https://api.chess.com/pub/club/thailand/members resolves.

Martin_Stahl

I think it worked. 

 

Use

var request = new XMLHttpRequest();

request.open('GET','https://api.chess.com/pub/club/thailand/members');

request.send();

JSON.parse(request.responseText);

 

You can of course, add the results into a variable, but that should show it's actually returning content.

VirtualKnightJoakim

That does not work for me:

var request = new XMLHttpRequest();
request.open('GET','https://api.chess.com/pub/club/thailand/members');
request.send();
JSON.parse(request.responseText);

 

https://api.chess.com/pub/club/thailand/members resolves.

Nevfy

@VirtualKnightJoakim  Try to perform your code consequently. In your second example JSON.parse(request.responseText); probably have nothing yet to parse, because request is not yet fulfilled.

VirtualKnightJoakim

I get an error before that. The script worked for me just a few days ago.

var request = new XMLHttpRequest();
request.open('GET','https://api.chess.com/pub/club/thailand/members');
request.send();


 

https://api.chess.com/pub/club/thailand/members resolves.

VirtualKnightJoakim

If someone could share a script snippets that works for them, I could play around with it. Thanks in advance!

Nevfy

The code above works well for me. Maybe, you shall try to use another browser.

VirtualKnightJoakim

Now my original script works again. Not sure if the problem was on my side or not. In any event, thanks everyone for help troubleshooting!

var request = new XMLHttpRequest();
request.open('GET','https://api.chess.com/pub/club/thailand/members',false);
request.send();
var response = JSON.parse(request.responseText);
response= response.weekly;
var list = '';
var d = new Date();
for(member of response){if (new Date(+member.joined*1000) < new Date('Sun Aug 14 2021 09:50:43 GMT-0400')) list += '@' + member.username + ', ' + '\r\n'};
console.log(list);