# Get the workspace

> The lab this key acts in, with its name — so an integration can show which lab it is writing to, and stop if it has been pointed at the wrong one.

Source: https://docs.xplantpro.com/docs/api/account/list-workspaces

`GET https://app.xplantpro.com/api/v1/workspaces`

- Required scope: `read:workspace`
- Credentials: workspace API key (`xpk_`)
- Idempotency-Key: ignored on this endpoint

A key belongs to one workspace, so the list has exactly one entry even when the person who created the key belongs to several labs. It is a list so that your code does not change shape if that ever changes. Takes no paging parameters.

## Example

**curl**

```bash
curl https://app.xplantpro.com/api/v1/workspaces \
  -H "Authorization: Bearer $XPLANT_API_KEY"
```

**JavaScript**

```js
import { XPlantClient } from "@shmaplex/xplant-sdk";

const client = new XPlantClient({ apiKey: process.env.XPLANT_API_KEY });

const [workspace] = await client.workspaces.list();
console.log(workspace.name);
```

**Python**

```python
import os
import requests

resp = requests.get(
    "https://app.xplantpro.com/api/v1/workspaces",
    headers={"Authorization": f"Bearer {os.environ['XPLANT_API_KEY']}"},
    timeout=10,
)
body = resp.json()
if not body["ok"]:
    raise RuntimeError(f"{resp.status_code} {body['code']}: {body['error']}")
workspaces = body["data"]
```

## Response

`200` with `{ "ok": true, "data": … }`. `data` is an array. Lists have no total: a page shorter than your `limit` is the last one. See [Pagination](https://docs.xplantpro.com/docs/pagination.md).

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | Yes | — |
| `name` | string | Yes | The lab's name as it appears in xPlant. |
| `type` | string | Yes | `lab` for a lab, `team` for a group inside one. |

```json title="Response"
{
  "ok": true,
  "data": [
    {
      "id": "8c2d4f6a-1b3e-4a5c-9d7e-0f1a2b3c4d5e",
      "name": "Riverside Propagation Lab",
      "type": "lab"
    }
  ]
}
```

| Response header | Meaning |
| --- | --- |
| `X-Request-Id` | Identifies this request. Include it when you contact support. |

## Errors

| Status | Code | When |
| --- | --- | --- |
| `401` | `UNAUTHORIZED` | The key is missing, malformed or revoked, or its owner is no longer a member of the workspace. |
| `402` | `PAID_PLAN_REQUIRED` | The workspace's plan does not include the API. The full API is included with xPlant+ Teams and Enterprise; on Hobby and Pro Lab, keys can connect devices only. |
| `403` | `FORBIDDEN` | The key lacks a scope this operation requires, or its owner's current role in the workspace cannot use it — a key never does more than its owner can in xPlant. `error` names the scope, and for a role, the role it needs. |
| `403` | `DEVICE_TOKEN_NOT_ACCEPTED` | A device token was sent; this operation needs a workspace API key. |
| `429` | `RATE_LIMIT_EXCEEDED` | Too many requests for this key, device token or workspace. Wait `Retry-After` seconds. |
| `500` | `WORKSPACE_QUERY_FAILED` | The workspace could not be read. Retry later. |

Branch on `code`, never on the `error` text. See [Errors](https://docs.xplantpro.com/docs/errors.md).
