Edit a row in a table in Nextcloud Tables
One script reply has been approved by the moderators Verified
Created by marcel klehr12 595 days ago Picked 10 times
Submitted by nextcloud Bun
Verified 61 days ago
1
import createClient, { type Middleware } from "openapi-fetch";
2

3
export async function main(
4
  nextcloud: RT.Nextcloud,
5
  rowId: number,
6
  columnId: number,
7
  value: string,
8
) {
9

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

21
  try {
22

23
    const resp = await client.PUT("/index.php/apps/tables/api/1/rows/{rowId}", {
24
      params: {
25
        header: {
26
          "OCS-APIRequest": true,
27
        },
28
        query: {
29
          format: "json",
30
        },
31
        path: {
32
          rowId: rowId,
33
        },
34

35
      },
36
      body: {
37
        data: {
38
          [columnId]: value,
39
        }
40
      },
41
    });
42

43
    console.debug('RESPONSE', resp.data)
44

45
    return {
46

47
      [columnId]: value,
48

49
    }
50

51
  } catch (e) {
52

53
    console.debug('error', e)
54

55
  }
56

57
  return {}
58

59
}
Other submissions