Consume Nextcloud webdav API via user credentials

I would like to upload a document via API by providing my user credentials. I’m using axios as my http client.

So I followed this

https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html#uploading-files

and came up with the following NodeJs code, unfortunately I can’t test the upload function because I’m struggling with the session flow. The login response returns a 404. How do I sign in correctly? And where do I have to provide my credentials? This application is not a Nextcloud app, it’s just a basic API consumer.

import { readFileSync } from "fs";
import axios from "axios";

async function bootstrap() {
  try {
    // ### Login ###

    const tokenResponse = await axios.post("https://cloud.computech.de/index.php/login/v2");
    const { poll, login } = tokenResponse.data;
    const { token, endpoint } = poll;
    const loginResponse = await axios.post(endpoint, { token }); // !! returns 404 !!
    const { server, loginName, appPassword } = loginResponse.data;

    // ### Uploading a new file ###

    const fileContent: Buffer = readFileSync("./test.csv");
    await axios.put("https://cloud.foo.com/remote.php/dav/files/myUsername/shared/test.csv", fileContent);
  } catch (error) {
    throw error;
  }
}
bootstrap();

Thanks for help

Login flow will start a process to create a app password (https://docs.nextcloud.com/server/18/developer_manual/client_apis/LoginFlow/index.html for all the details).

If you just want to upload a file it’s probably enough to pass username and password (a manually created app password is probably better) as auth to axios.

  auth: {
    username: 'janedoe',
    password: 's00pers3cret'
  },