Query group list for collection creation

I have read that the public api is only partially supported, but is there a way to query a list of groups? Ultimately, I want to create collections for each group that I have synced using Bitwarden Directory Connector.

I tried a request of GET /api/organizations/<org_id>/groups. But I don’t know how to get past the user authentication. I attempted the following options but none worked.
curl https://$DOMAIN/api/organizations/$ORG_ID -d '{"username":$USER,"password":$PASS}'
curl -X POST https://$DOMAIN/api/organizations/$ORG_ID -H "Content-Type: application/json" \ -d '{ "client_id": "organization.$ORG_ID", "client_secret": $SECRET, "scope": "api.organization", "grant_type": "client_credentials" }'
curl -H "Authorization: Bearer $SECRET" https://$DOMAIN/api/organizations/$ORG_ID

Also, is there a way to show the id of groups in the web ui? I tried creating a collection with the Bitwarden Client but I couldn’t find the id of the group I wanted to specify. I could only find the external id in the web UI so I tried with that and it did not work.

The request JSON I passed to bw is something like the following:

{"organizationId": $ORG_ID,"name": "TEST", "groups": [{"id": $EXTERNAL_ID, "readOnly": false, "hidePasswords": false, "manage": true}]}

I fixed and rewrote in typescript to get the correct access token, but requesting the organization details, I am still unauthorized.

async function authenticate() {
	const response = await fetch(`${DOMAIN}/identity/connect/token`, {
		method: "POST",
		headers: {
			"Content-Type": "application/x-www-form-urlencoded",
		},
		body: new URLSearchParams({
			device_type: DEVICE_TYPE,
			device_name: DEVICE_NAME,
			device_identifier: DEVICE_IDENTIFIER,
			scope: "api.organization",
			grant_type: "client_credentials",
			client_id: CLIENT_ID,
			client_secret: CLIENT_SECRET,
		}),
	});

	const tokenResponse = await response.json();
	const accessToken = tokenResponse.access_token;
	return accessToken;
}

async function getOrganizations(token: string) {
	const response = await fetch(`${DOMAIN}/api/organizations/${ORG_ID}/groups`, {
		method: "GET",
		headers: {
			Authorization: `Bearer ${token}`,
		},
	});

  if (response.status === 200 || response.ok === true) {
    return response;
  }
  console.error(response);
}

I authenticated correctly now and got the access_token, but I still get an error getting organization details

Here is the code in typescript:

async function authenticate() {
	const response = await fetch(`${DOMAIN}/identity/connect/token`, {
		method: "POST",
		headers: {
			"Content-Type": "application/x-www-form-urlencoded",
		},
		body: new URLSearchParams({
			device_type: DEVICE_TYPE,
			device_name: DEVICE_NAME,
			device_identifier: DEVICE_IDENTIFIER,
			scope: "api.organization",
			grant_type: "client_credentials",
			client_id: CLIENT_ID,
			client_secret: CLIENT_SECRET,
		}),
	});

	const tokenResponse = await response.json();
	const accessToken = tokenResponse.access_token;
	return accessToken;
}

async function getOrganizations(token: string) {
	const response = await fetch(`${DOMAIN}/api/organizations/${ORG_ID}/groups`, {
		method: "GET",
		headers: {
			Authorization: `Bearer ${token}`,
		},
	});

  if (response.status === 200 || response.ok === true) {
    return response;
  }
  console.error(response);
}