Http Request with Login

Hello,

How i can do the same code with homey script, i tried a lot of things, but without success.

        const payload = {
            email: myemail,
            password: mypassword,
        };
        const response = await client.post(`${baseUrl}/web/login`, payload);

AFAIK string values should be double quoted, and never put a comma after the last payload value :

const payload = {
            email: "myemail",
            password: "mypassword"
        };
        const response = await client.post(`${baseUrl}/web/login`, payload);

Single quotes and trailing commas are perfectly fine here. The issue is that client.post() obviously isn’t anything; instead, fetch() should be used.

1 Like

I tried with different solution => no success, and I tried also on Postman and it’s ok. (see picture)
But I saw, the system load a cookie in the headers (I remove it), but it load it again.
Is it possible to add a cookie on fetch ?

Yes: Using the Fetch API - Web APIs | MDN

For cookies, use the Cookie header.