aurbano / robinhood-node

:chart_with_upwards_trend: NodeJS client for Robinhood Trading :fire:
https://aurbano.github.io/robinhood-node
MIT License
694 stars 185 forks source link

Error when trying to authenticate #107

Closed JacobRichardson closed 3 years ago

JacobRichardson commented 4 years ago

Code being executed:

require('dotenv').config();

const credentials = {
    username: process.env.ROBINHOOD_USERNAME,
    password: process.env.ROBINHOOD_PASSWORD
}

var Robinhood = require('robinhood')(credentials, function () {

    //Robinhood is connected and you may begin sending commands to the api.

    Robinhood.quote_data('GOOG', function (error, response, body) {
        if (error) {
            console.error(error);
            process.exit(1);
        }
        console.log(body);
    });

});

Expected result

// A little explanation, sample response JSON...

Stock quote data of the stock with the ticker simple 'GOOG'. This is the code from the README.md. I am trying to use this snippet in order to authenticate my Robinhood account and get started using the rest of the package.

Actual behavior

// Either the error you received or the JSON that was returned

I just started using the npm package today so it should be the latest version. Originally, I was getting a 200 error because I had MFA on my account turned on. I turned it off and I started getting this 400 error when trying to authenticate. I am using the dotenv package to bring in my credentials. I logged the credentials object to the console and the values were correct. There should be no issue with the .env file. The .env file contains: ROBINHOOD_USERNAME=ACTUAL_USERNAME ROBINHOOD_PASSWORD=ACTUAL_PASSWORD

Below is the actual terminal output I am receiving.

./node_modules/robinhood/src/robinhood.js:145 throw new Error('token not found ' + JSON.stringify(httpResponse)); ^ Error: token not found {"statusCode":400,"body":{"detail":"This version of Robinhood is no longer supported. Please update your app or use Robinhood for Web to log in to your account."},"headers":{"date":"Mon, 06 Jul 2020 20:15:36 GMT","content-type":"application/json","content-length":"137","connection":"close","server":"openresty","allow":"POST, OPTIONS","x-robinhood-api-version":"0.0.0","content-security-policy":"default-src 'none'","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","x-xss-protection":"1; mode=block","access-control-allow-origin":"https://robinhood.com","vary":"Origin"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"api.robinhood.com","port":443,"hostname":"api.robinhood.com","hash":null,"search":null,"query":null,"pathname":"/oauth2/token/","path":"/oauth2/token/","href":"https://api.robinhood.com/oauth2/token/"},"method":"POST","headers":{"Host":"api.robinhood.com","Accept":"*/*","Accept-Encoding":"gzip, deflate","Referer":"https://robinhood.com/","Origin":"https://robinhood.com","content-type":"application/x-www-form-urlencoded","content-length":154}}} at Request._callback (./node_modules/robinhood/src/robinhood.js:145:17) at Request.self.callback (./node_modules/request/request.js:185:22) at Request.emit (events.js:198:13) at Request. (./node_modules/request/request.js:1154:10) at Request.emit (events.js:198:13) at IncomingMessage. (./node_modules/request/request.js:1076:12) at Object.onceWrapper (events.js:286:20) at IncomingMessage.emit (events.js:203:15) at endReadableNT (_stream_readable.js:1129:12) at process._tickCallback (internal/process/next_tick.js:63:19)

Reproducing

// Please provide a bit of context for the code snippet, were you authenticated?

No, I am not authenticated. I was trying to get authenticated in order to use this package. I copied the code from the README.md. I even tried the auth token snippet from the README.md and that was not working either. I was getting the same error. I am not sure if I am doing anything wrong though. If you need more information please let me know. Any feedback, help, or advice would be greatly appreciated. Thank you!

ncrmro commented 4 years ago

I am also having this issue, I've been able to authenticate fine with robin_stocks which is a python robinhood api client.

ncrmro commented 4 years ago

I'm thinking of pulling the token out of the headers when you open up robinhood in the web inspector.

bhaktatejas922 commented 3 years ago

Having the same issue here

JacobRichardson commented 3 years ago

This issue does not appear to be happening anymore. The above code segment appears to be working now. Is anyone still having the same issue?

JacobRichardson commented 3 years ago

I haven't heard back from anyone about still having the issue so I am going to close this issue.