1
Get user metadata
One script reply has been approved by the moderators Verified
Created by jaller94 545 days ago Viewed 2428 times
0
Submitted by jaller94 Deno
Verified 545 days ago
1
// https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#user-metadata
2
// Should return an XML document on success.
3
type Nextcloud = {
4
  baseUrl: string;
5
  username: string;
6
  password: string;
7
};
8
export async function main(nextcloud_res: Nextcloud, userId: string) {
9
  const resp = await fetch(
10
    `${nextcloud_res.baseUrl}/ocs/v1.php/cloud/users/${encodeURIComponent(
11
      userId,
12
    )}`,
13
    {
14
      headers: {
15
        Authorization:
16
          "Basic " +
17
          btoa(nextcloud_res.username + ":" + nextcloud_res.password),
18
        "OCS-APIRequest": "true",
19
      },
20
    },
21
  );
22
  if (!resp.ok) {
23
    throw Error(`HTTP Error ${resp.status} - ${await resp.text()}`);
24
  }
25
  return await resp.text();
26
}
27