# Preview Analytics Panel Transform

Try transform code on a panel's sources before you save it with Update Analytics Panel. Nothing is saved.

`POST https://connect.mindcloud.co/v2/analytics/pages/:pageId/panels/:panelId/transform-preview`

Permissions: `analytics:page:edit`.

## Parameters

### Path

- `pageId` (string, required): The page id, from List Analytics Pages.
- `panelId` (string, required): The panel id, from Get Analytics Page.

### Headers

- `X-Company-Id` (string): Optional. The id of the organization to act in. Leave it out to act in the API key's own organization. Here a key acts in another organization only as one of its members: with "Use this key across all of your organizations" on, in an organization its creator belongs to with a role. Child organizations and MindCloud staff access do not reach this endpoint. Every response's X-Company-Id header names the organization it acted in. See [Organizations](https://mindcloud.co/docs/api/rest/introduction/organizations).

### Body

- `code` (string, required): The code to try.
  JavaScript function body receiving each source as a named input ({ alias }) and returning rows, as transformCode on Update Analytics Panel.
- `limit` (number): How many rows to answer, 1-1000.
  How many rows to answer, 1-1000. Defaults to 100.
  Default: `100`
- `offset` (number): How many rows to skip.
  How many rows to skip. Defaults to 0.
  Default: `0`

## Example request

```bash
curl --request POST \
  --url 'https://connect.mindcloud.co/v2/analytics/pages/Pq7Lm2Xc9RtA/panels/Kd4Rw8Zn1VbQ/transform-preview' \
  --header 'Authorization: Bearer $MINDCLOUD_API_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
  "code": "return orders.map((row) => ({ ...row, total: row.amount * row.quantity }));",
  "limit": 100,
  "offset": 0
}'
```

## Response fields

- `columns` (array of string): The column names the rows carry, in order.
- `rows` (array of objects): The rows in this window, as objects keyed by column.
- `rowCount` (number): How many rows there are in all.
- `offset` (number): Where this window starts.
- `nextOffset` (number): The offset of the next window, or null when this is the last.
