1

Nextcloud Tables: List all tables

by
Published Jul 23, 2024

List all tables of the given user in the tables app

Script nextcloud Verified

The script

Submitted by nextcloud Bun
Verified 112 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
  • Submitted by marcel klehr12 Deno
    Created 595 days ago
    1
    import * as wmill from "npm:windmill-client@1";
    2
    import * as tb from "https://raw.githubusercontent.com/marcelklehr/nextcloud-client-deno/1629b11dc919b99d8dfadf2870a02128a24333fa/tables/index.ts";
    3
    
    
    4
    // fill the type, or use the +Resource type to get a type-safe reference to a resource
    5
    // type Postgresql = object
    6
    
    
    7
    export async function main(
    8
      nextcloudResource: string,
    9
      userId: string | null = null,
    10
      useAppApiAuth: boolean = false,
    11
    ) {
    12
      const ncResource = await wmill.getResource(
    13
        nextcloudResource,
    14
      );
    15
      const config = new tb.Configuration({
    16
        username: userId || ncResource.username,
    17
        password: ncResource.password,
    18
        basePath: ncResource.baseUrl,
    19
        middleware: [{
    20
          async pre(context) {
    21
            if (!context.url.includes("?")) {
    22
              context.url += "?";
    23
            } else {
    24
              context.url += "&";
    25
            }
    26
            context.url += "format=json";
    27
            return context;
    28
          },
    29
        }],
    30
        ...(useAppApiAuth && ({
    31
          headers: {
    32
            "AA-VERSION": "2.3.0",
    33
            "EX-APP-ID": "flow",
    34
            "EX-APP-VERSION": "1.0.0",
    35
            "AUTHORIZATION-APP-API": btoa(
    36
              `${userId || ncResource.username}:${ncResource.password}`,
    37
            ),
    38
          },
    39
        })),
    40
      });
    41
      const api = new tb.Api1Api(config);
    42
    
    
    43
      return await api.api1List();
    44
    }
    45