export type CreateApiUsersUserIdRelationshipsUserGroupsArgs = {user_id: string, body: {data: Array<{type: string, id: string}>}}; export type CreateApiUsersUserIdRelationshipsUserGroupsOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Add normal user to group(s) * * POST /users/{user_id}/relationships/user-groups */ export const createApiUsersUserIdRelationshipsUserGroups = async (args: CreateApiUsersUserIdRelationshipsUserGroupsArgs, options: CreateApiUsersUserIdRelationshipsUserGroupsOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.api+json") headers.set('accept', "application/vnd.api+json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.user_id))}/relationships/user-groups${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return (await res.json()) as unknown };