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 595 days ago Picked 14 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
) {
6

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

18
  try {
19

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

29
      },
30
    });
31

32
    console.debug('RESPONSE', resp.data)
33

34
    return resp.data
35

36
  } catch (e) {
37

38
    console.debug('error', e)
39

40
  }
41

42
  return {}
43

44
}
Other submissions