List user IDs
One script reply has been approved by the moderators Verified

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

Created by jaller94 1259 days ago Picked 1 time
Submitted by jaller94 Deno
Verified 311 days ago
1
// Should return an XML document on success
2
type Nextcloud = {
3
  baseUrl: string;
4
  username: string;
5
  password: string;
6
};
7
export async function main(nextcloud_res: Nextcloud) {
8
  const resp = await fetch(`${nextcloud_res.baseUrl}/ocs/v1.php/cloud/users`, {
9
    headers: {
10
      Authorization:
11
        "Basic " + btoa(nextcloud_res.username + ":" + nextcloud_res.password),
12
      "OCS-APIRequest": "true",
13
    },
14
  });
15
  if (!resp.ok) {
16
    throw Error(`HTTP Error ${resp.status} - ${await resp.text()}`);
17
  }
18
  return await resp.text();
19
}
20