# Switch user workspace

`POST /api/auth/switch-workspace`

Switch the authenticated user to a different workspace (tenant). Returns new authentication tokens for the target workspace.

Authentication: no security requirement declared for this operation.

Request body: application/json (required)

Type: object

Schema: [SwitchWorkspaceDTO](https://sourcey-gauzy.pages.dev/api-reference/models/switchworkspacedto/index.md)

- `tenantId` (required)
  Type: string
  
  The tenant ID to switch to
  
  Example:
  
  ```json
  "550e8400-e29b-41d4-a716-446655440000"
  ```

Responses:

- 200: Successfully switched workspace. Returns new authentication tokens.

- 400: Invalid workspace switch request. Check that tenantId is a valid UUID.

- 401: User not authenticated or does not have access to the workspace.

## Examples

### cURL

```bash
curl -X POST 'http://localhost:3000/api/auth/switch-workspace' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "tenantId": "550e8400-e29b-41d4-a716-446655440000"
}'
```

### JavaScript

```javascript
const body = `{
  "tenantId": "550e8400-e29b-41d4-a716-446655440000"
}`;

const response = await fetch('http://localhost:3000/api/auth/switch-workspace', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "tenantId": "550e8400-e29b-41d4-a716-446655440000"
}'''

response = requests.post(
    'http://localhost:3000/api/auth/switch-workspace',
    data=body.encode('utf-8'),
    headers={
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
