> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://www.comet.com/docs/opik/llms.txt.

# Create view version

POST http://localhost:5173/api/v1/private/views/{id}/versions
Content-Type: application/json

Add a version to a view and make it current

Reference: https://www.comet.com/docs/opik/reference/rest-api/views/create-view-version

## Servers

- `http://localhost:5173/api` (Local server, default)
- `https://www.comet.com/opik/api` (Opik Cloud)

## Request

### Path parameters

- `id` (string, required)

### Body (application/json)

This endpoint expects a ViewVersionCreate.

- `type` (enum, required) — View type
  - Allowed values: `html`
- `engine_version` (integer, required) — HTML contract version the view was written against
- `inputs` (map from string to ViewInput, required) — Input name to data source, one or several; the view receives one data object with a key per input
- `html` (string, required) — The view: HTML, CSS and script rendered in a sandboxed iframe
- `summary` (string, optional) — What changed, one line
- `author` (enum, optional) — Who produced the version: user (default), ollie or agent. Informational only
  - Allowed values: `user`, `ollie`, `agent`
- `libraries` (list of string, optional) — Libraries the host loads before the view runs; none when omitted

## Response

### 201

Created

- `view_id` (string, optional)
- `version` (integer, optional)
- `author` (enum, optional)
  - Allowed values: `user`, `ollie`, `agent`
- `summary` (string, optional)
- `type` (enum, optional)
  - Allowed values: `html`
- `engine_version` (integer, optional) — HTML contract version the view was written against
- `inputs` (map from string to ViewInput, optional)
- `libraries` (list of string, optional) — Libraries the host loads before the view runs; omitted when it uses none
- `html` (string, optional)
- `created_at` (datetime, optional)
- `created_by` (string, optional)

## Errors

### 404 Not Found Error

View not found

- `any`

### 422 Unprocessable Entity Error

Unprocessable Content

- `code` (integer, optional)
- `message` (string, optional)
- `details` (string, optional)

## Types

### ViewInput

A data source of a view; the host resolves it and passes the result under the input name

- `kind` (enum, required) — Source type
  - Allowed values: `query`
- `query_id` (string, required) — The saved query to run
- `columns` (map from string to string, optional) — The columns the author saw when it ran the query, name to type. Informational

## Examples

**Request**

```json
{
  "type": "html",
  "engine_version": 1,
  "html": "string"
}
```

**Response**

```json
{
  "view_id": "string",
  "version": 1,
  "author": "user",
  "summary": "string",
  "type": "html",
  "engine_version": 1,
  "inputs": {},
  "libraries": [
    "string"
  ],
  "html": "string",
  "created_at": "2024-01-15T09:30:00Z",
  "created_by": "string"
}
```

**SDK Code**

```python
import requests

url = "http://localhost:5173/api/v1/private/views/id/versions"

payload = {
    "type": "html",
    "engine_version": 1,
    "html": "string"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'http://localhost:5173/api/v1/private/views/id/versions';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"type":"html","engine_version":1,"html":"string"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://localhost:5173/api/v1/private/views/id/versions"

	payload := strings.NewReader("{\n  \"type\": \"html\",\n  \"engine_version\": 1,\n  \"html\": \"string\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("http://localhost:5173/api/v1/private/views/id/versions")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"type\": \"html\",\n  \"engine_version\": 1,\n  \"html\": \"string\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://localhost:5173/api/v1/private/views/id/versions")
  .header("Content-Type", "application/json")
  .body("{\n  \"type\": \"html\",\n  \"engine_version\": 1,\n  \"html\": \"string\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://localhost:5173/api/v1/private/views/id/versions', [
  'body' => '{
  "type": "html",
  "engine_version": 1,
  "html": "string"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("http://localhost:5173/api/v1/private/views/id/versions");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"type\": \"html\",\n  \"engine_version\": 1,\n  \"html\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "type": "html",
  "engine_version": 1,
  "html": "string"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:5173/api/v1/private/views/id/versions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```