I get following error with this code, not sure what I'm doing wrong..
const Avanza = require('avanza')
const avanza = new Avanza()
console.log(avanza)
var user = 'fellmanfilip'
avanza.authenticate({
username: user,
password: '***********',
totpSecret: '****************************************'
}).then(async () => {
console.log("Successfully authenticated for %s", user)
console.log("Trying to fetch current positions for %s", user)
const positions = await avanza.getPositions()
console.log("Successfully fetched current positions for %s", user)
console.log(positions)
}).catch(e => { console.log(`Failed to fetch current positions for ${user} due to\n`, e) })
PS C:\Users\ffellman\private_projects> node .\display_savings.js
Avanza {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_credentials: null,
_socket: null,
_authenticated: false,
_authenticationSession: null,
_authenticationTimeout: 1440,
_pushSubscriptionId: null,
_reauthentication: null,
_customerId: null,
_securityToken: null,
_backOffTimestamps: {},
_socketHandshakeTimer: null,
_socketSubscriptions: {},
_socketMonitor: null,
_socketLastMetaConnect: 0,
_adviceTimeout: 30000,
_socketConnected: false,
_socketMessageCount: 1,
_socketClientId: null,
[Symbol(kCapture)]: false
}
Successfully authenticated for fellmanfilip
Trying to fetch current positions for fellmanfilip
Failed to fetch current positions for fellmanfilip due to
TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-AuthenticationSession"
at ClientRequest.setHeader (node:_http_outgoing:647:3)
at new ClientRequest (node:_http_client:284:14)
at Object.request (node:https:360:10)
at C:\Users\ffellman\private_projects\node_modules\avanza\dist\index.js:53:23
at new Promise (<anonymous>)
at request (C:\Users\ffellman\private_projects\node_modules\avanza\dist\index.js:52:10)
at C:\Users\ffellman\private_projects\node_modules\avanza\dist\index.js:934:9
at new Promise (<anonymous>)
at Avanza.call (C:\Users\ffellman\private_projects\node_modules\avanza\dist\index.js:930:12)
at Avanza.getPositions (C:\Users\ffellman\private_projects\node_modules\avanza\dist\index.js:600:17) {
code: 'ERR_HTTP_INVALID_HEADER_VALUE'
}
I get following error with this code, not sure what I'm doing wrong..