1
Edit a row in a table in Nextcloud Tables
One script reply has been approved by the moderators Verified
Created by marcel klehr12 138 days ago Viewed 354 times
0
Submitted by nextcloud Bun
Verified 9 days ago
1
import * as wmill from "windmill-client";
2
import createClient, { type Middleware } from "openapi-fetch";
3

4
type Nextcloud = {
5
  baseUrl: string,
6
  password: string,
7
  username: string
8
};
9

10
export async function main(
11
  ncResource: Nextcloud,
12

13
  userId: string | null = null,
14

15
  rowId: number,
16

17
  columnId: number,
18

19
  value: string,
20

21
  useAppApiAuth: boolean = false,
22
) {
23

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

43
  try {
44

45
    const resp = await client.PUT("/index.php/apps/tables/api/1/rows/{rowId}", {
46
      params: {
47
        header: {
48
          "OCS-APIRequest": true,
49
        },
50
        query: {
51
          format: "json",
52
        },
53
        path: {
54
          rowId: rowId,
55
        },
56

57
      },
58
      body: {
59
        data: {
60
          [columnId]: value,
61
        }
62
      },
63
    });
64

65
    console.debug('RESPONSE', resp.data)
66

67
    return {
68

69
      [columnId]: value,
70

71
    }
72

73
  } catch (e) {
74

75
    console.debug('error', e)
76

77
  }
78

79
  return {}
80

81
}
Other submissions