1

Get user metadata

by
Published Oct 1, 2022

https://docs.nextcloud.com/server/latest/developer_manual//client_apis/OCS/ocs-api-overview.html#user-metadata

Script ocs Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 9 days ago
1
//native
2

3
// https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#user-metadata
4
// Should return an XML document on success.
5
type Nextcloud = {
6
  baseUrl: string;
7
  username: string;
8
  password: string;
9
};
10
export async function main(nextcloud_res: Nextcloud, userId: string) {
11
  const resp = await fetch(
12
    `${nextcloud_res.baseUrl}/ocs/v1.php/cloud/users/${encodeURIComponent(
13
      userId,
14
    )}`,
15
    {
16
      headers: {
17
        Authorization:
18
          "Basic " +
19
          btoa(nextcloud_res.username + ":" + nextcloud_res.password),
20
        "OCS-APIRequest": "true",
21
      },
22
    },
23
  );
24
  if (!resp.ok) {
25
    throw Error(`HTTP Error ${resp.status} - ${await resp.text()}`);
26
  }
27
  return await resp.text();
28
}
29

Other submissions
  • Submitted by jaller94 Deno
    Created 401 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