Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node client with umami cloud - unable to parse response as json #8

Open
boly38 opened this issue Nov 6, 2024 · 0 comments
Open

node client with umami cloud - unable to parse response as json #8

boly38 opened this issue Nov 6, 2024 · 0 comments

Comments

@boly38
Copy link

boly38 commented Nov 6, 2024

Hi

Context:
using umami client targetting an umami cloud website instance :

I'm trying to retrieve node client response as json.
and here is what I get

I changed the end of the script to show response

const response = await umamiClient.track(event);
console.log(`✮ Event ${JSON.stringify(event)}`);

// 1st test
// const json = await response.json();
// console.log(`Event response JSON : ${json}`);

// second test
// const text = await response.text();
// const base64ToString = Buffer.from(text, "base64").toString();
// console.log(`Event response base64ToString : ${base64ToString}`);

1st example console result is

✮ Event {"url":"/home","title":"title of /home","name":"button-click","data":{"color":"red"}}
undefined:1
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e------------REDACTED--------DZ7fFPYaLhXYo1iVf7mC41Cbk74-wGzQ
SRGQzxfq4
^

SyntaxError: Unexpected token 'e', "eyJhbGciOi"... is not valid JSON
    at JSON.parse (<anonymous>)
    at parseJSONFromBytes (node:internal/deps/undici/undici:4306:19)
    at successSteps (node:internal/deps/undici/undici:4288:27)
    at fullyReadBody (node:internal/deps/undici/undici:2724:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async consumeBody (node:internal/deps/undici/undici:4297:7)

Second example console result is

✮ Event {"url":"/home","title":"title of /home","name":"button-click","data":{"color":"red"}}
Event response base64ToString : {"alg":"HS256","typ":"JWT"}{"id":"2e5bdff5---REDACTED--ce98dec9eb59","websiteId":"b1eb5f43--REDACTED--44549dddd65e","visitId":"9c53435d--REDACTED--05c660a
7c840","browser":null,"os":null,"country":"FR","subdivision1":"FR-IDF","city":"Paris","iat":1730924085}☼↔��Y��Z�wloF��G�q<{)|l
�q1�1f{�

I just redacted some part of the id.

Is this a client or backend (cloud) issue ?

I suspect backend because I even tried to use a patched version of the client adding "Accept: application/json to the request but I got the same issue.
It's a kind of base64 of the (json + other data)...

Any hint appreciated.

regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant