fhqvst / avanza

A JavaScript client for the unofficial Avanza API
MIT License
229 stars 59 forks source link

can't make demo code to work but it do authenticate #79

Closed theycallmetyson closed 1 year ago

theycallmetyson commented 2 years ago

following the first example it gets successfully authenticated but when it come to the getPositions() i get TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-AuthenticationSession". any idea of how to solve it?

require('dotenv').config()
const Avanza = require('avanza')

const avanza = new Avanza()

const credentials = {
    username: process.env.AVANZA_USERNAME,
    password: process.env.AVANZA_PASSWORD,
    totpSecret: process.env.AVANZA_TOTP_SECRET
}

avanza.authenticate(credentials).then(async () => {
    console.log('Authenticated')

    const positions = await avanza.getPositions()
    console.log(positions)

}).catch(err => {
    console.log(err)
})
[nodemon] starting `node ./src/server.js`
Authenticated
TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-AuthenticationSession"
    at ClientRequest.setHeader (node:_http_outgoing:606:3)
    at new ClientRequest (node:_http_client:271:14)
    at Object.request (node:https:360:10)
    at C:\Users\tyson.la\Projects\tensai-vexa-api\node_modules\avanza\dist\index.js:53:23
    at new Promise (<anonymous>)
    at request (C:\Users\tyson.la\Projects\tensai-vexa-api\node_modules\avanza\dist\index.js:52:10)
    at C:\Users\tyson.la\Projects\tensai-vexa-api\node_modules\avanza\dist\index.js:934:9
    at new Promise (<anonymous>)
    at Avanza.call (C:\Users\tyson.la\Projects\tensai-vexa-api\node_modules\avanza\dist\index.js:930:12)
    at Avanza.getPositions (C:\Users\tyson.la\Projects\tensai-vexa-api\node_modules\avanza\dist\index.js:600:17) {
  code: 'ERR_HTTP_INVALID_HEADER_VALUE'
}
fruddq commented 2 years ago

Have the same problem

filipfellman commented 1 year ago

@theycallmetyson Did you solve this? I get the same error, I have created a issue here https://github.com/fhqvst/avanza/issues/85

origooo commented 1 month ago

I had the same issue until I activated 2FA/MFA. For a while, I forgot to actually complete the activation on avanza.se after I got the initial key.