# Switch to a different organization within the current workspace

`POST /api/auth/switch-organization`

Authentication: no security requirement declared for this operation.

Request body: application/json (required)

Type: object

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

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

Responses:

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

- 400: Invalid organization switch request. Check that organizationId is a valid UUID.

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

## Examples

### cURL

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

### JavaScript

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

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

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

### Python

```python
import requests

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

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