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 595 days ago Picked 10 times
Submitted by nextcloud Bun
Verified 21 days ago
1
import createClient, { type Middleware } from "openapi-fetch";
2

3
export async function main(
4
  nextcloud: RT.Nextcloud,
5
  tableId: number,
6
) {
7

8
  const client = createClient<paths>({ baseUrl: nextcloud.baseUrl });
9
  const authMiddleware: Middleware = {
10
    async onRequest({ request, options }) {
11
      // fetch token, if it doesn’t exist
12
      // add Authorization header to every request
13
      request.headers.set("Authorization", `Basic ${btoa((nextcloud.userId) + ':' + nextcloud.token)}`);
14
      return request;
15
    },
16
  };
17
  client.use(authMiddleware);
18

19
  const resp = await client.GET("/index.php/apps/tables/api/1/tables/{tableId}/columns", {
20
    params: {
21
      header: {
22
        "OCS-APIRequest": true,
23
      },
24
      query: {
25
        format: "json",
26
      },
27
      path: {
28
        tableId: tableId,
29
      },
30

31
    },
32
  });
33

34
  return resp.data;
35

36
}
Other submissions