Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone,
I'm trying to adapt the following example from the Qlik API documentation here to my use case, but I’m running into a strange error:
It seems that the application cannot be opened with openAppSession().
Here’s my code:
What I’ve checked so far:
The app exists and I can open it manually in Qlik Cloud.
The OAuth2 credentials and scopes seem correct.
I am the owner of the app.
Questions:
Does openAppSession() work with OAuth2 client credentials, or is it only supported for certain authentication flows?
Could the "Going away" error indicate a websocket connection problem or missing scope?
Are there specific permissions needed to call getDoc() in this context?
Has anyone encountered this error before, and how did you resolve it?
Thanks in advance for your help!
Hey @nammaitran, could you please add below code for printing all the websocket events? Seems something is cutting websocket connection.
const appSession = qix.openAppSession(appId);
const events = appSession.onWebSocketEvent((event) => {
console.log("event: ", event);
});
Hello @alex_colombo, thanks a lot for your reply
I added the code you suggested for printing WebSocket events, and here’s what I got:
event: { eventType: 'opened', appId: '393d1c65-d852-4c30-95cc-286bc90132bf' }
event: {
eventType: 'suspended',
appId: '393d1c65-d852-4c30-95cc-286bc90132bf',
initiator: 'network',
code: 1001,
reason: ''
}
event: {
eventType: 'closed',
appId: '393d1c65-d852-4c30-95cc-286bc90132bf',
code: 1001,
reason: '',
wasClean: true
...
}
So the connection opens, then immediately gets suspended and finally closed with code 1001 (going away).
To be honest, I’m not entirely sure how to interpret this. From what I understand:
Any hints on how to debug this further would be really helpful.
Thanks again for your support!
Full log:
Error: Failed to open app 393d1c65-d852-4c30-95cc-286bc90132bf: Going away.
at file:///C:/Qlik/CLI/node_modules/@qlik/api/chunks/qix-bnv1_Kxc.js:356:36
at async file:///C:/Qlik/CLI/get_private_sheets.mjs:19:15 {
code: -1,
enigmaError: true,
original: CloseEvent {
[Symbol(kTarget)]: <ref *1> WebSocket {
_events: [Object: null prototype] {
open: [Function: onOpen] {
[Symbol(kIsForOnEventAttribute)]: true,
[Symbol(kListener)]: [Function: bound onOpen]
},
close: [Function: onClose] {
[Symbol(kIsForOnEventAttribute)]: true,
[Symbol(kListener)]: [Function: bound onClose]
},
error: [Function: onError] {
[Symbol(kIsForOnEventAttribute)]: true,
[Symbol(kListener)]: [Function: bound onError]
},
message: [Function: onMessage] {
[Symbol(kIsForOnEventAttribute)]: true,
[Symbol(kListener)]: [Function: bound onMessage]
}
},
_eventsCount: 4,
_maxListeners: undefined,
_binaryType: 'nodebuffer',
_closeCode: 1001,
_closeFrameReceived: true,
_closeFrameSent: true,
_closeMessage: Buffer(0) [Uint8Array] [],
_closeTimer: Timeout {
_idleTimeout: -1,
_idlePrev: null,
_idleNext: null,
_idleStart: 1010,
_onTimeout: null,
_timerArgs: undefined,
_repeat: null,
_destroyed: true,
[Symbol(refed)]: true,
[Symbol(kHasPrimitive)]: false,
[Symbol(asyncId)]: 53,
[Symbol(triggerId)]: 32,
[Symbol(kAsyncContextFrame)]: undefined
},
_errorEmitted: false,
_extensions: {},
_paused: false,
_protocol: '',
_readyState: 3,
_receiver: Receiver {
_events: [Object: null prototype] {},
_writableState: WritableState {
highWaterMark: 16384,
length: 0,
corked: 0,
onwrite: [Function: bound onwrite],
writelen: 0,
bufferedIndex: 0,
pendingcb: 0,
[Symbol(kState)]: 1091466620,
[Symbol(kBufferedValue)]: null,
[Symbol(kWriteCbValue)]: null
},
_maxListeners: undefined,
_allowSynchronousEvents: true,
_binaryType: 'nodebuffer',
_extensions: {},
_isServer: false,
_maxPayload: 104857600,
_skipUTF8Validation: false,
_bufferedBytes: 0,
_buffers: [],
_compressed: false,
_payloadLength: 2,
_mask: undefined,
_fragmented: 0,
_masked: false,
_fin: true,
_opcode: 8,
_totalPayloadLength: 0,
_messageLength: 0,
_fragments: [],
_errored: false,
_loop: false,
_state: 0,
_eventsCount: 0,
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false,
[Symbol(websocket)]: [Circular *1]
},
_sender: Sender {
_extensions: {},
_socket: TLSSocket {
_tlsOptions: {
allowHalfOpen: undefined,
pipe: false,
secureContext: [SecureContext],
isServer: false,
requestCert: true,
rejectUnauthorized: true,
session: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined,
enableTrace: undefined,
pskCallback: undefined,
highWaterMark: undefined,
onread: undefined,
signal: undefined
},
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'xxxxxxxxxx.eu.qlikcloud.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype] {
close: [Function: onSocketCloseDestroySSL],
end: [Function: onReadableStreamEnd],
error: [Function: socketOnError],
newListener: [Array],
connect: undefined,
secure: [Function: onConnectSecure],
data: undefined,
drain: undefined
},
_eventsCount: 5,
connecting: false,
_hadError: false,
_parent: null,
_host: 'xxxxxxxxxx.eu.qlikcloud.com',
_closeAfterHandlingError: false,
_readableState: ReadableState {
highWaterMark: 16384,
buffer: [],
bufferIndex: 0,
length: 0,
pipes: [],
awaitDrainWriters: null,
[Symbol(kState)]: 60295028
},
_writableState: WritableState {
highWaterMark: 16384,
length: 0,
corked: 0,
onwrite: [Function: bound onwrite],
writelen: 0,
bufferedIndex: 0,
pendingcb: 0,
[Symbol(kState)]: 1091450228,
[Symbol(kBufferedValue)]: null,
[Symbol(kWriteCbValue)]: null
},
allowHalfOpen: false,
_maxListeners: undefined,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: null,
autoSelectFamilyAttemptedAddresses: [ '2a05:d018:1703:a204:4a99:1a97:d796:8111:443' ],
timeout: 0,
write: [Function: writeAfterFIN],
[Symbol(alpncallback)]: null,
[Symbol(res)]: null,
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 32,
[Symbol(kHandle)]: null,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kSetNoDelay)]: true,
[Symbol(kSetKeepAlive)]: false,
[Symbol(kSetKeepAliveInitialDelay)]: 0,
[Symbol(kBytesRead)]: 784,
[Symbol(kBytesWritten)]: 1042,
[Symbol(connect-options)]: {
rejectUnauthorized: true,
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA',
checkServerIdentity: [Function: checkServerIdentity],
minDHSize: 1024,
allowSynchronousEvents: true,
autoPong: true,
protocolVersion: 13,
maxPayload: 104857600,
skipUTF8Validation: false,
perMessageDeflate: true,
followRedirects: false,
maxRedirects: 10,
headers: [Object],
socketPath: undefined,
hostname: undefined,
protocol: undefined,
timeout: undefined,
method: 'GET',
host: 'xxxxxxxxxxxx.eu.qlikcloud.com',
path: undefined,
port: 443,
createConnection: [Function: tlsConnect],
defaultPort: 443,
_defaultAgent: [Agent],
servername: 'xxxxxxxxxxxxx.eu.qlikcloud.com',
singleUse: true
},
[Symbol(websocket)]: undefined
},
_firstFragment: true,
_compress: false,
_bufferedBytes: 0,
_queue: [],
_state: 0,
onerror: [Function: senderOnError],
[Symbol(websocket)]: [Circular *1]
},
_socket: TLSSocket {
_tlsOptions: {
allowHalfOpen: undefined,
pipe: false,
secureContext: SecureContext { context: SecureContext {} },
isServer: false,
requestCert: true,
rejectUnauthorized: true,
session: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined,
enableTrace: undefined,
pskCallback: undefined,
highWaterMark: undefined,
onread: undefined,
signal: undefined
},
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'xxxxxxxxxxxxxx.eu.qlikcloud.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype] {
close: [Function: onSocketCloseDestroySSL],
end: [Function: onReadableStreamEnd],
error: [Function: socketOnError],
newListener: [ [Function: keylogNewListener], [Function: newListener] ],
connect: undefined,
secure: [Function: onConnectSecure],
data: undefined,
drain: undefined
},
_eventsCount: 5,
connecting: false,
_hadError: false,
_parent: null,
_host: 'xxxxxxxxxxx.eu.qlikcloud.com',
_closeAfterHandlingError: false,
_readableState: ReadableState {
highWaterMark: 16384,
buffer: [],
bufferIndex: 0,
length: 0,
pipes: [],
awaitDrainWriters: null,
[Symbol(kState)]: 60295028
},
_writableState: WritableState {
highWaterMark: 16384,
length: 0,
corked: 0,
onwrite: [Function: bound onwrite],
writelen: 0,
bufferedIndex: 0,
pendingcb: 0,
[Symbol(kState)]: 1091450228,
[Symbol(kBufferedValue)]: null,
[Symbol(kWriteCbValue)]: null
},
allowHalfOpen: false,
_maxListeners: undefined,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: null,
autoSelectFamilyAttemptedAddresses: [ '2a05:d018:1703:a204:4a99:1a97:d796:8111:443' ],
timeout: 0,
write: [Function: writeAfterFIN],
[Symbol(alpncallback)]: null,
[Symbol(res)]: null,
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 32,
[Symbol(kHandle)]: null,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kSetNoDelay)]: true,
[Symbol(kSetKeepAlive)]: false,
[Symbol(kSetKeepAliveInitialDelay)]: 0,
[Symbol(kBytesRead)]: 784,
[Symbol(kBytesWritten)]: 1042,
[Symbol(connect-options)]: {
rejectUnauthorized: true,
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA',
checkServerIdentity: [Function: checkServerIdentity],
minDHSize: 1024,
allowSynchronousEvents: true,
autoPong: true,
protocolVersion: 13,
maxPayload: 104857600,
skipUTF8Validation: false,
perMessageDeflate: true,
followRedirects: false,
maxRedirects: 10,
headers: {
Authorization: 'Bearer <redacted>',
'Sec-WebSocket-Version': 13,
'Sec-WebSocket-Key': 'lEIEfofesnDrWsYJmLFIzg==',
Connection: 'Upgrade',
Upgrade: 'websocket',
'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits'
},
socketPath: undefined,
hostname: undefined,
protocol: undefined,
timeout: undefined,
method: 'GET',
host: 'xxxxx.eu.qlikcloud.com',
path: undefined,
port: 443,
createConnection: [Function: tlsConnect],
defaultPort: 443,
_defaultAgent: Agent {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object: null prototype],
requests: [Object: null prototype] {},
sockets: [Object: null prototype] {},
freeSockets: [Object: null prototype] {},
keepAliveMsecs: 1000,
keepAlive: true,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 0,
maxCachedSessions: 100,
_sessionCache: [Object],
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
servername: 'xxxxxxxxxxxx.eu.qlikcloud.com',
singleUse: true
},
[Symbol(websocket)]: undefined
},
_bufferedAmount: 0,
_isServer: false,
_redirects: 0,
_autoPong: true,
_url: 'wss://xxxxxxxxxxx.eu.qlikcloud.com/app/393d1c65-d852-4c30-95cc-286bc90132bf?reloadUri=wss%3A%2F%2Fxxxxxxxxxxx.eu.qlikcloud.com%2Fsense%2Fapp%2F393d1c65-d852-4c30-95cc-286bc90132bf',
_req: null,
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
[Symbol(kType)]: 'close',
[Symbol(kCode)]: 1001,
[Symbol(kReason)]: '',
[Symbol(kWasClean)]: true
}
}
This is wierd, seems something is cutting websocket connection. Where are you running this code? It is on your local machine or deployed somewhere?
Hello @alex_colombo I'm running it on my local machine
could you please share your OAuth client configuration?
Try also to remove the scope prop from setDefaultHostConfig, or at least separate values with comma.