1
Nextcloud Tables: Get all columns of a table
One script reply has been approved by the moderators Verified

Get all columns of the given table in the Nextcloud Tables app

Created by marcel klehr12 179 days ago Viewed 350 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
  userId: string | null = null,
13
  tableId: number,
14
  useAppApiAuth: boolean = false,
15
) {
16

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

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

48
    },
49
  });
50

51
  return resp.data;
52

53
}
Other submissions