---
search:
  tags:
    - Views
    - POST
seo:
  description: >-
    Save a new View in the caller's organization. Reference for the POST
    /v1/views/create endpoint in the Roboto REST API.
sidebar:
  label: Create view
  badge: POST
title: Create view
type: openapi-operation
---
Save a new View in the caller's organization.

Requires ``can_create_views`` on the organization. The caller becomes the View's author:
the one person, besides the organization's admins and owners, who can delete it or change who
can see it.

The View is private unless the request asks for ``organization`` visibility. Its
``definition`` is stored as sent and returned as stored, so keep the whole object and send
it back whole when updating; the ``scheme`` field inside it names the version of its shape,
and readers should dispatch on that rather than assume the current one.

#### Access control
 - requires_org
 - Restricted tokens need the API scope `api.everything_else`

`POST /v1/views/create`

**Request body** (`application/json`, required)

- `name` (string, required)
- `target` (QueryTarget, required) — Kind of resource a query searches.
- `definition` (ViewDefinition, required) — Saved contents of a View: the search its author made, and how its results are shown. A definition records what the author entered, RoboQL text or filter controls, and the client builds a query from it each time the View loads. It does not store a :py:class:\`\~roboto.query.QuerySpecification\`, because a query specification cannot express a relative date such as "the last 7 days": converting the filter fixes its dates, and the View would show the week it was saved in from then on. Filter controls are recorded as :py:class:\`\~roboto.query.SavedFilters\`, so any caller can build a View's filters. The Roboto web app converts them to a query when the View loads; RoboQL text runs as written. At most one of \`\`roboql\`\` and \`\`filters\`\` is set, and a definition with neither filters nothing. Constructing a definition raises \`\`pydantic.ValidationError\`\` when it sets both, or when its \`\`scheme\`\` is neither \`\`"view\_v1"\`\` nor \`\`"view\_v2"\`\`. The View's target is not part of its definition; \`\`ViewRecord.target\`\` holds it. Carried in \`\`ViewRecord.definition\`\`, :py:attr:\`\~roboto.domain.views.CreateViewRequest.definition\` and :py:attr:\`\~roboto.domain.views.UpdateViewRequest.definition\`.
- `visibility` (ViewVisibility) — Visibility of a View: who can see it, chosen when the View is created and reported when it is read. Visibility decides only who can read a View. Whatever its visibility, a View can be edited only by its author, users and groups granted \`\`editor\`\` on it, and admins and owners of its organization.

Request body example:

```json
{
  "name": "string",
  "target": "collections",
  "definition": {
    "scheme": "view_v2",
    "roboql": null,
    "filters": null,
    "display": {
      "visible_columns": [
        "string"
      ],
      "sort": {
        "kind": "default"
      },
      "page_size": null
    }
  },
  "visibility": "private"
}
```

**Responses**

- `200` — OK
- `400` — A conversation with Roboto's AI is longer than the AI model can read at once. The conversation's messages and tool results, together with the AI's instructions, exceed the model's context window. The exception does not carry the token count or the model's limit.
- `401` — The caller's token is expired or malformed.
- `403` — The request would take the user or organization past a limit on a resource, such as AI credits.
- `404` — The request names an API route Roboto does not serve.
- `409` — The request conflicts with an existing resource, such as by giving a name another resource already has.
- `410` — The resource the request names is missing or has expired.
- `500` — Roboto reported an error that this release of the SDK cannot match to a specific exception class. Reported for an element of a :py:class:\`\~roboto.http.BatchResponse\` whose error names a code this release defines no class for, or that arrived without a code, without a message, or as text that is not an error envelope at all. It carries whatever code and message Roboto sent, so a caller handling the failure still learns what went wrong; when no message could be read, the message is the error's raw text. :py:meth:\`\~roboto.domain.devices.Device.create\_session\` raises it, and :py:meth:\`\~roboto.domain.devices.Device.create\_sessions\` lists it in the batch's :py:attr:\`\~roboto.http.BatchResponse.failed\`. The error envelope carries no status code, so \`\`http\_status\_code\`\` reports the 500 inherited from \`\`RobotoDomainException\`\` rather than the status the failure had.
- `501` — The request asks for an operation this deployment of Roboto does not provide.
- `503` — Roboto could not accept the request, such as under heavy load. Retrying later may succeed.
- `504` — Roboto ran out of time while processing the request. Retrying may succeed.
- `507` — The response to the request is larger than Roboto can send. Retrying the same request fails the same way; request less data at a time.

Response example, 200:

```json
{
  "data": {
    "view_id": "string",
    "name": "string",
    "org_id": "string",
    "target": "collections",
    "definition": {
      "scheme": "view_v2",
      "roboql": null,
      "filters": null,
      "display": {
        "visible_columns": [
          "string"
        ],
        "sort": {
          "kind": "default"
        },
        "page_size": null
      }
    },
    "schema_version": 0,
    "created": "2019-08-24T14:15:22Z",
    "created_by": "string",
    "modified": "2019-08-24T14:15:22Z",
    "modified_by": "string",
    "visibility": null
  }
}
```
