Particle.createUser not working (missing params)

(‘Missing parameters. “username” and “password” are required’): But I have the username and password in my code. Please let me know what am I missing.

I also noticed the sample code here at the link below has Syntax Errors. I think missing ) right before 1st .then and extra } second from the last line.

https://docs.particle.io/reference/javascript/#create-user

I corrected them and run the code below:

particle.createUser({username:'my_email@testemail.com',password:'xxxxxxxiiiivvv' }).then(function(data) {
    var loginPromise = particle.login('my_email@testemail.com', 'xxxxxxxiiiivvv');
    loginPromise.then(
     function(data) {
       console.log('Login successful! access_token:', data.access_token);
     },
     function(err) {
       console.log('Login failed:', err);
     }
   );
 });

get the response below (‘Missing parameters. “username” and “password” are required’):

Login failed: { statusCode: 400,
  errorDescription: 'HTTP error 400 from /oauth/token - Missing parameters. "username" and "password" are required',
  error: 
   { [Error: Bad Request]
     original: null,
     response: 
      Response {
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        res: [Object],
        request: [Object],
        req: [Object],
        links: {},
        text: '{\n  "error": "invalid_client",\n  "error_description": "Missing parameters. \\"username\\" and \\"password\\" are required"\n}',
        body: [Object],
        files: {},
        buffered: true,
        headers: [Object],
        header: [Object],
        statusCode: 400,
        status: 400,
        statusType: 4,
        info: false,
        ok: false,
        redirect: false,
        clientError: true,
        serverError: false,
        error: [Object],
        accepted: false,
        noContent: false,
        badRequest: true,
        unauthorized: false,
        notAcceptable: false,
        forbidden: false,
        notFound: false,
        charset: 'utf-8',
        type: 'application/json',
        setEncoding: [Function: bound ],
        redirects: [] },
     status: 400 },
  body: 
   { error: 'invalid_client',
     error_description: 'Missing parameters. "username" and "password" are required' } }

Actually, that does seem to work (after fixing the syntax error. If you add a console.log(data); above the var loginPromise, you’ll see the (successful return).
What doesn’t work is logging in immediately thereafter, since you’ve yet to confirm the account by clicking the link in the email that’s been generated. So there needs to be an interface in which you can insert the right numbers (or so it seems from looking at the code).

@Moors7, yes, you are right. createUser works but promise login was the one having an issue. I have separated the login piece for different function for now.

1 Like