Nextcloud Talk: List all rooms

List all talk rooms that a user has access to.

Script nextcloud Verified

by marcel klehr12 · 7/23/2024

The script

Submitted by nextcloud Bun
Verified 86 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
  const res = await client.GET("/ocs/v2.php/apps/spreed/api/{apiVersion}/room", {
19
    params: {
20
      header: {
21
        "OCS-APIRequest": true,
22
      },
23
      query: {
24
        format: "json",
25
      },
26
      path: {
27
        apiVersion: "v4",
28
      },
29

30
    },
31
  });
32

33
  return await res.data;
34

35
}
Other submissions
  • Submitted by marcel klehr12 Deno
    Created 568 days ago
    1
    import * as wmill from "npm:windmill-client@1";
    2
    import * as tb from "https://raw.githubusercontent.com/marcelklehr/nextcloud-client-deno/6f973bfdcaed0d8b4f35b6cf5d0368d8bec73ed4/talk/index.ts";
    3
    
    
    4
    export async function main(
    5
      nextcloudResource: string,
    6
      userId: string | null = null,
    7
      useAppApiAuth: boolean = false,
    8
    ) {
    9
      const ncResource = await wmill.getResource(
    10
        nextcloudResource,
    11
      );
    12
      const config = new tb.Configuration({
    13
        username: userId || ncResource.username,
    14
        password: ncResource.password,
    15
        basePath: ncResource.baseUrl,
    16
        middleware: [{
    17
          async pre(context) {
    18
            if (!context.url.includes("?")) {
    19
              context.url += "?";
    20
            } else {
    21
              context.url += "&";
    22
            }
    23
            context.url += "format=json";
    24
            return context;
    25
          },
    26
        }],
    27
        ...(useAppApiAuth && ({
    28
          headers: {
    29
            "AA-VERSION": "2.3.0",
    30
            "EX-APP-ID": "flow",
    31
            "EX-APP-VERSION": "1.0.0",
    32
            "AUTHORIZATION-APP-API": btoa(
    33
              `${userId || ncResource.username}:${ncResource.password}`,
    34
            ),
    35
          },
    36
        })),
    37
      });
    38
      const api = new tb.RoomApi(config);
    39
    
    
    40
      const res = await api.roomGetRoomsRaw({
    41
        apiVersion: "v4",
    42
        oCSAPIRequest: true,
    43
      });
    44
      return await res.raw.json();
    45
    }
    46