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

# List Workspaces

> Retrieve all workspaces that the authenticated user has access to

## List Workspaces

Retrieves all workspaces that the authenticated user has access to, including their associated accounts.

### Request

<RequestExample>
  ```bash theme={null}
  curl -X GET "https://postsyncer.com/api/v1/workspaces" \
    -H "Authorization: Bearer YOUR_API_TOKEN"
  ```
</RequestExample>

### Response

<ResponseField name="data" type="array">
  Array of workspace objects
</ResponseField>

<ResponseExample>
  ```json theme={null}
  {
    "data": [
      { 
        "id": 12,
        "name": "abdulmejidshemsuawel",
        "slug": "abdulmejidshemsuawel",
        "type": "PERSONAL",
        "logo": null,
        "timezone": "Africa/Addis_Ababa",
        "language": "en",
        "accounts": [
          {
              "id": 136,
              "platform": "twitter",
              "username": "heyabdulmejid",
              "name": "Abdul",
              "avatar": "https://pbs.twimg.com/profile_images/1878383928995684352/3Xw5HTsk_400x400.jpg"
          }
        ]
      },
      { 
        "id": 14,
        "name": "postsyncer",
        "slug": "postsyncer",
        "type": "ORGANIZATION",
        "logo": null,
        "timezone": "Africa/Addis_Ababa",
        "language": "en",
        "accounts": [
          {
              "id": 140,
              "platform": "twitter",
              "username": "postsyncer",
              "name": "PostSyncer",
              "avatar": "https://pbs.twimg.com/profile_images/1878383928995684352/3Xw5HTsk_400x400.jpg"
          }
        ]
      }
    ]
  }
  ```
</ResponseExample>

### Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://postsyncer.com/api/v1/workspaces" \
    -H "Authorization: Bearer YOUR_API_TOKEN"
  ```

  ```javascript Node.js theme={null}
  const axios = require('axios');

  const getWorkspaces = async () => {
    try {
      const response = await axios.get('https://postsyncer.com/api/v1/workspaces', {
        headers: {
          'Authorization': 'Bearer YOUR_API_TOKEN'
        }
      });
      
      console.log('Workspaces:', response.data);
      return response.data;
    } catch (error) {
      console.error('Error fetching workspaces:', error.response?.data || error.message);
    }
  };

  getWorkspaces();
  ```

  ```php PHP theme={null}
  <?php

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://postsyncer.com/api/v1/workspaces');
  curl_setopt($ch, CURLOPT_HTTPGET, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Authorization: Bearer YOUR_API_TOKEN'
  ]);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);

  if ($httpCode === 200) {
      $workspaces = json_decode($response, true);
      echo "Found " . count($workspaces['data']) . " workspaces";
  } else {
      echo "Error: " . $response;
  }
  ?>
  ```

  ```python Python theme={null}
  import requests

  headers = {
      'Authorization': 'Bearer YOUR_API_TOKEN'
  }

  response = requests.get(
      'https://postsyncer.com/api/v1/workspaces',
      headers=headers
  )

  if response.status_code == 200:
      workspaces = response.json()
      print(f"Found {len(workspaces['data'])} workspaces")
      for workspace in workspaces['data']:
          print(f"Workspace {workspace['id']}: {workspace['name']}")
          print(f"  Accounts: {len(workspace['accounts'])}")
  else:
      print(f"Error: {response.status_code}")
      print(response.text)
  ```
</CodeGroup>

### Error Codes

<ResponseField name="401" type="Unauthorized">
  Missing or invalid API token
</ResponseField>

<ResponseField name="403" type="Forbidden">
  Token does not have 'workspaces' permission
</ResponseField>
