1
Nextcloud Tables: List all tables
One script reply has been approved by the moderators Verified

List all tables of the given user in the tables app

Created by marcel klehr12 179 days ago Viewed 355 times
0
Submitted by nextcloud Bun
Verified 9 days ago
1
import * as wmill from "windmill-client";
2
import createClient, { type Middleware } from "openapi-fetch";
3

4
type Nextcloud = {
5
  baseUrl: string,
6
  password: string,
7
  username: string
8
};
9

10
export async function main(
11
  ncResource: Nextcloud,
12

13
  userId: string | null = null,
14

15
  useAppApiAuth: boolean = false,
16
) {
17

18
  const client = createClient<paths>({ baseUrl: ncResource.baseUrl });
19
  const authMiddleware: Middleware = {
20
    async onRequest({ request, options }) {
21
      // fetch token, if it doesn’t exist
22
      // add Authorization header to every request
23
      request.headers.set("Authorization", `Basic ${btoa((userId || ncResource.username) + ':' + ncResource.password)}`);
24
      if (useAppApiAuth) {
25
        request.headers.set("AA-VERSION", "2.3.0",);
26
        request.headers.set("EX-APP-ID", "flow",);
27
        request.headers.set("EX-APP-VERSION", "1.0.1",);
28
        request.headers.set("AUTHORIZATION-APP-API", btoa(
29
          `${userId || ncResource.username}:${ncResource.password}`,
30
        ));
31
      }
32
      return request;
33
    },
34
  };
35
  client.use(authMiddleware);
36

37
  try {
38

39
    const resp = await client.GET("/index.php/apps/tables/api/1/tables", {
40
      params: {
41
        header: {
42
          "OCS-APIRequest": true,
43
        },
44
        query: {
45
          format: "json",
46
        },
47

48
      },
49
    });
50

51
    console.debug('RESPONSE', resp.data)
52

53
    return resp.data
54

55
  } catch (e) {
56

57
    console.debug('error', e)
58

59
  }
60

61
  return {}
62

63
}
Other submissions