Get a form submission from Nextcloud Forms
One script reply has been approved by the moderators Verified
Created by marcel klehr12 486 days ago Picked 11 times
Submitted by nextcloud Bun
Verified 352 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
  userId: string | null = null,
13
  formId: string,
14
  submissionId: number,
15
  useAppApiAuth: boolean = false,
16
) {
17

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

37
  try {
38
    const resp = await client.GET("/ocs/v2.php/apps/forms/api/v3/forms/{formId}/submissions", {
39
      params: {
40
        header: {
41
          "OCS-APIRequest": true,
42
        },
43
        query: {
44
          format: "json",
45
        },
46
        path: {
47
          formId: formId,
48
        },
49

50
      },
51
    });
52

53
    const submission = resp.data.ocs.data.submissions.find(s => s.id === submissionId)
54
    //console.debug('SUBMISSION', submission)
55
    return {
56
      submission,
57
    }
58
  } catch(e) {
59
    console.debug('error', e)
60
  }
61

62
}
Other submissions