1
Nextcloud Tables: Create a row in a table
One script reply has been approved by the moderators Verified

Create a row in a table in Nextcloud Tables

Created by marcel klehr12 179 days ago Viewed 367 times
0
Submitted by nextcloud Bun
Verified 10 days ago
1
import * as wmill from "windmill-client";
2
import createClient, { type Middleware } from "openapi-fetch";
3

4
interface Data {
5
  [p: number]: any
6
}
7

8
type Nextcloud = {
9
  baseUrl: string,
10
  password: string,
11
  username: string
12
};
13

14
export async function main(
15
  ncResource: Nextcloud,
16
  userId: string | null = null,
17
  tableId: number,
18
  data: Data,
19
  useAppApiAuth: boolean = false,
20
) {
21

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

41
  const resp = await client.POST("/index.php/apps/tables/api/1/tables/{tableId}/rows", {
42
    params: {
43
      header: {
44
        "OCS-APIRequest": true,
45
      },
46
      query: {
47
        format: "json",
48
      },
49
      path: {
50
        tableId: tableId,
51
      },
52

53
    },
54
    body: {
55
        data: data
56
      },
57
  });
58

59
  return resp.data;
60

61
}
Other submissions