Particle Javascript 404 error

I’m trying to do a simple login with the Particle javascript library but can’t seem to get it to work. I’ve copied directly from the docs and have triple checked that I can login with that account in build.particle.io and the CLI.

This is the boiled down code:


<script type="text/javascript" src="//cdn.jsdelivr.net/particle-api-js/5/particle.min.js"></script>

var particle = new Particle();
particle.login({username: '[my username]', password: '[my password]'}).then(
        function(data){
            console.log('API call completed on promise resolve: ', data.access_token);
        },
        function(err) {
            console.log('API call completed on promise fail: ', err);
        }
);

Here is what I get:

I pulled everything from here.

Could you give this a try, seems to work for me?

<html>
  <head>
    <title>Particle Login Example</title>
	
    <script type="text/javascript" src="http://cdn.jsdelivr.net/particle-api-js/5/particle.min.js"></script>
  </head>

  <body>
    <script>
		var particle = new Particle();
	
		particle.login({username: '[USERNAME]', password: '[PASSWORD]'}).then(
		  function(data){
			console.log('API call completed on promise resolve: ', data.body.access_token);
		  },
		  function(err) {
			console.log('API call completed on promise fail: ', err);
		  }
		);
	
    </script>
  </body>
</html>

@Moors7 -

That works now…but other than excluding the http:// and not properly navigating the result of the promise I can’t figure out why the original promise failed… I even ran the original code and it no longer errors (even though it returns “undefined” for data.access_token since that exists in data.body).

I was running this last night ~12 hours ago with the failed result before posting it this morning because I figured it might be a fluke in the system.

On that note, is there an uptime / status for all Particle services somewhere?

I found the status page btw:
http://status.particle.io/

Don’t see any issues with logins for yesterday. Glad it’s working now though.

So, I was still having my issue after the fact, but it looks like the cdn version of the javascript file (the one linked in the docs) is out of date and has a bug where it links to https://api.particle.io/ where it includes an extra "/" at the end of it. Thus, all calls to the api look like https://api.particle.io//oauth for example. Removing the slash seems to resolve it, but it's also resolved in the latest on github, so I just pulled that instead:

https://raw.githubusercontent.com/spark/particle-api-js/master/dist/particle.min.js

1 Like