> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Workspaces

> Create workspaces, invite members, manage roles and share applications across a team.

<Info>
  Workspaces are exposed by the `Workspaces` interface embedded in `rest.Rest`. They are available on **Standard, Pro and Enterprise** plans.
</Info>

```go theme={null}
client := rest.NewClient(os.Getenv("SQUARECLOUD_API_KEY"))
defer client.Close()

api := rest.New(client)
```

## Creating a workspace

```go theme={null}
workspace, err := api.CreateWorkspace("Acme")
if err != nil {
	panic(err)
}

fmt.Println(workspace.ID)
```

The name must be 1–32 characters long, and creating a workspace requires an active paid plan.

## Listing workspaces

`api.GetWorkspaces()` returns every workspace where the authenticated user is owner or member.

```go theme={null}
workspaces, err := api.GetWorkspaces()
if err != nil {
	panic(err)
}

for _, ws := range workspaces {
	fmt.Println(ws.Name, ws.ID)
}
```

## Fetching a single workspace

Workspace IDs are UUID v4 values without hyphens (32 hex chars).

```go theme={null}
workspace, err := api.GetWorkspace("1234567890abcdef1234567890abcdef")
if err != nil {
	panic(err)
}

fmt.Println(workspace.Name)
fmt.Println(workspace.Owner)
fmt.Println(workspace.Members)
fmt.Println(workspace.Applications)
```

## Inviting members

Inviting a member is a two-step handshake — the invitee proves consent by generating a short-lived code from **their** client, and the owner consumes it.

```go theme={null}
// 1. From the invitee's own SDK client
otherClient := rest.NewClient(os.Getenv("OTHER_USER_API_KEY"))
defer otherClient.Close()
otherAPI := rest.New(otherClient)

code, err := otherAPI.GetWorkspaceInviteCode()
if err != nil {
	panic(err)
}

// 2. From the workspace owner's client
err = api.AddWorkspaceMember("1234567890abcdef1234567890abcdef", code, "maintain")
if err != nil {
	panic(err)
}
```

<Note>
  The invite code is generated by the user who is going to **join** the workspace, not by the owner. It is single-use and expires after **5 minutes** — generate it, hand it to the owner/admin, and consume it promptly.
</Note>

### Roles

| Role              | Description                                                  |
| ----------------- | ------------------------------------------------------------ |
| `owner` / `admin` | Full workspace management                                    |
| `maintain`        | Operational access to shared applications                    |
| `manager`         | Monitoring plus application lifecycle (start, stop, restart) |
| `view`            | Read-only access                                             |

## Changing a member's role

```go theme={null}
err := api.UpdateWorkspaceMember("1234567890abcdef1234567890abcdef", "abcdef0123456789abcdef01", "admin")
if err != nil {
	panic(err)
}
```

## Removing a member

```go theme={null}
err := api.RemoveWorkspaceMember("1234567890abcdef1234567890abcdef", "abcdef0123456789abcdef01")
if err != nil {
	panic(err)
}
```

## Sharing applications

```go theme={null}
err := api.AddWorkspaceApplication("1234567890abcdef1234567890abcdef", "abc123def456abc123def456")
if err != nil {
	panic(err)
}

err = api.RemoveWorkspaceApplication("1234567890abcdef1234567890abcdef", "abc123def456abc123def456")
```

## Leaving or deleting a workspace

<Warning>
  Deleting a workspace is irreversible and only available to the owner.
</Warning>

```go theme={null}
// As a member
err := api.LeaveWorkspace("1234567890abcdef1234567890abcdef")

// As the owner (irreversible)
err = api.DeleteWorkspace("1234567890abcdef1234567890abcdef")
```
