Protobox

Switch Workspace

Switch the current user's active workspace context.

Users can belong to multiple workspaces. This endpoint changes the active workspace for subsequent API calls, affecting which data and resources are accessible.

Request
curl -X POST "https://platform.protobox.ai/api/v1/auth/switch-workspace" \
  -H "Authorization: Bearer <access_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "workspace_id": "ws_789"
  }'
const response = await fetch('https://platform.protobox.ai/api/v1/auth/switch-workspace', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer ' + accessToken,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    workspace_id: 'ws_789'
  })
});

const { data } = await response.json();
console.log('Switched to workspace:', data.workspace.name);
import requests

response = requests.post(
    'https://platform.protobox.ai/api/v1/auth/switch-workspace',
    headers={'Authorization': f'Bearer {access_token}'},
    json={'workspace_id': 'ws_789'}
)

workspace = response.json()['data']['workspace']
Response
{
  "success": true,
  "data": {
    "workspace": {
      "id": "ws_789",
      "name": "Marketing Team",
      "slug": "marketing-team",
      "role": "member",
      "permissions": [
        "read:tools",
        "write:tools",
        "read:knowledge",
        "write:knowledge"
      ]
    },
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }
}
{
  "success": false,
  "error": {
    "code": "WORKSPACE_ACCESS_DENIED",
    "message": "User does not have access to this workspace"
  }
}