# Organization

> The team workspaces of the NoClick app you're in, as its workspace settings show them.

```python
acme = noclick.Organization.create("Acme Ops")
noclick.Organization.invite(acme, "sam@example.com", role="admin")
for member in noclick.Organization.members(acme):
    print(member["email"], member["role"])
```

A team workspace's members are people, so every call is a signed-in person's own: a client holding a person's
session token (never a key, which refuses them all). Not `noclick.Workspace`, which is one of Work's spaces.
Members, invites and single sign-on come back as the API answers them (dicts).

## Organization

```typescript
class Organization
```

A team workspace you're in.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string` |  |
| `name` | `string` |  |
| `slug` | `string` |  |
| `role` | `string | null` | Your role in it: `owner`, `admin` or `member`. |
| `iconUrl` | `string | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### Organization.list

```typescript
static list(options?: Options): Promise<Organization[]>
```

The team workspaces you're in, each with your `role`.

Parameters:

- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: Each team workspace you're in, as an `Organization`.

### Organization.get

```typescript
static get(organization: Ref, options?: Options): Promise<Organization>
```

One you're in, by id.

Parameters:

- `organization` (`Ref`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The `Organization`.

### Organization.create

```typescript
static create(
  name: string,
  options?: Options & { slug?: string },
): Promise<Organization>
```

Make a team workspace with you as its owner (`slug` made from the name when left out); your session acts in it
from then on. How many you may own is your plan's.

Parameters:

- `name` (`string`, required)
- `options.slug` (`string`)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The new `Organization`.

### Organization.update

```typescript
static update(
  organization: Ref,
  changes: { name?: string; settings?: JsonObject },
  options?: Options,
): Promise<JsonObject>
```

Rename it or change its settings (its owner or an admin).

Parameters:

- `organization` (`Ref`, required)
- `changes` (`{ name?: string; settings?: JsonObject }`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The team workspace as it now stands.

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### Organization.delete

```typescript
static delete(organization: Ref, options?: Options): Promise<void>
```

Delete it for good, its members and invites with it (its owner only).

Parameters:

- `organization` (`Ref`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

### Organization.slugAvailable

```typescript
static slugAvailable(slug: string, options?: Options): Promise<boolean>
```

Whether a new team workspace could take `slug`.

Parameters:

- `slug` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `True` when no team workspace has it.

### Organization.members

```typescript
static members(organization: Ref, options?: Options): Promise<JsonObject[]>
```

Its members, each with their `user_id`, `email` and `role`.

Parameters:

- `organization` (`Ref`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: Each member, with their `user_id`, `email`, `full_name` and `role`.

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### Organization.invite

```typescript
static invite(
  organization: Ref,
  email: string,
  options?: Options & { role?: "admin" | "member" },
): Promise<JsonObject>
```

Invite someone by email (its owner or an admin): they're emailed a link that joins them as `role`. How many people
it holds is its plan's. Answers the invite, with `email_sent`: `false` when its email couldn't go (`email_error`
says why), and the invite stands all the same, so share its link yourself.

Parameters:

- `organization` (`Ref`, required)
- `email` (`string`, required)
- `options.role` (`"admin" | "member"`, default `"member"`)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The invite, with `email_sent`: `False` when its email couldn't go (`email_error` says why), and the
invite stands all the same, so share its link yourself.

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### Organization.setRole

```typescript
static setRole(
  organization: Ref,
  userId: string,
  role: "admin" | "member",
  options?: Options,
): Promise<void>
```

Change a member's role (its owner or an admin; never the owner's).

Parameters:

- `organization` (`Ref`, required)
- `userId` (`string`, required)
- `role` (`"admin" | "member"`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

### Organization.removeMember

```typescript
static removeMember(
  organization: Ref,
  userId: string,
  options?: Options,
): Promise<void>
```

Take a member out (its owner or an admin; never the owner).

Parameters:

- `organization` (`Ref`, required)
- `userId` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

### Organization.transfer

```typescript
static transfer(
  organization: Ref,
  userId: string,
  options?: Options,
): Promise<void>
```

Hand it to another of its members (its owner only): they become its owner, you an admin.

Parameters:

- `organization` (`Ref`, required)
- `userId` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

### Organization.invites

```typescript
static invites(organization: Ref, options?: Options): Promise<JsonObject[]>
```

Its invites still waiting to be accepted.

Parameters:

- `organization` (`Ref`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: Each invite still waiting, with its `email`, `role` and when it expires.

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### Organization.revokeInvite

```typescript
static revokeInvite(
  organization: Ref,
  inviteId: string,
  options?: Options,
): Promise<void>
```

Call an invite off: its link stops working.

Parameters:

- `organization` (`Ref`, required)
- `inviteId` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

### Organization.acceptInvite

```typescript
static acceptInvite(token: string, options?: Options): Promise<JsonObject>
```

Join the team workspace an invite to your email asks you to.

Parameters:

- `token` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The `organization_id` and `organization_name` of the team workspace you joined.

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### Organization.switchTo

```typescript
static switchTo(organization: Ref | null, options?: Options): Promise<void>
```

Make the workspace your session acts in a team one you're in, or your own (`null`).

Parameters:

- `organization` (`Ref | null`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
