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

# Edit Artifact

> Applies patch operations to the latest version and writes a new version. Anchors and selectors must match exactly once. Send `base_version` to get `409 ARTIFACT_STALE` instead of editing a newer version.

Authenticate with a Tess API token in the `Authorization: Bearer` header. See the [Artifacts API guide](https://docs.tess.im/en/artifacts-api.md) for the full flow, permissions and ownership rules.

### **Code Examples**

```http cURL theme={null}
curl --request POST \
  --url 'https://api.tess.im/artifacts/artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f/edit' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'x-workspace-id: YOUR_WORKSPACE_ID' \
  --header 'Content-Type: application/json' \
  --data '{
    "base_version": 1,
    "operations": [
      {
        "op": "replace",
        "old": "$1.2M",
        "new": "$1.4M"
      }
    ]
  }'
```

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

const config = {
  method: 'post',
  url: 'https://api.tess.im/artifacts/artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f/edit',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'x-workspace-id': 'YOUR_WORKSPACE_ID',
    'Content-Type': 'application/json'
  },
  data: {
    "base_version": 1,
    "operations": [
      {
        "op": "replace",
        "old": "$1.2M",
        "new": "$1.4M"
      }
    ]
  }
};

try {
  const response = await axios(config);
  console.log(response.data);
} catch (error) {
  console.error(error);
}
```

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

url = "https://api.tess.im/artifacts/artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f/edit"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "x-workspace-id": "YOUR_WORKSPACE_ID",
    "Content-Type": "application/json"
}
payload = {
  "base_version": 1,
  "operations": [
    {
      "op": "replace",
      "old": "$1.2M",
      "new": "$1.4M"
    }
  ]
}

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

```php PHP theme={null}
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.tess.im/artifacts/artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f/edit",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode(["base_version" => 1, "operations" => [["op" => "replace", "old" => "\$1.2M", "new" => "\$1.4M"]]]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer YOUR_API_KEY",
    "x-workspace-id: YOUR_WORKSPACE_ID",
    "Content-Type: application/json"
  ]
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "Error: " . $err;
} else {
  echo $response;
}
```

```java Java theme={null}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.tess.im/artifacts/artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f/edit"))
    .header("Authorization", "Bearer YOUR_API_KEY")
    .header("x-workspace-id", "YOUR_WORKSPACE_ID")
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("{\n  \"base_version\": 1,\n  \"operations\": [\n    {\n      \"op\": \"replace\",\n      \"old\": \"$1.2M\",\n      \"new\": \"$1.4M\"\n    }\n  ]\n}"))
    .build();

HttpResponse<String> response = client.send(request,
    HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

```go Go theme={null}
package main

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

func main() {
    client := &http.Client{}
    req, err := http.NewRequest("POST", "https://api.tess.im/artifacts/artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f/edit", strings.NewReader(`{
  "base_version": 1,
  "operations": [
    {
      "op": "replace",
      "old": "$1.2M",
      "new": "$1.4M"
    }
  ]
}`))
    if err != nil {
        fmt.Println(err)
        return
    }

    req.Header.Add("Authorization", "Bearer YOUR_API_KEY")
    req.Header.Add("x-workspace-id", "YOUR_WORKSPACE_ID")
    req.Header.Add("Content-Type", "application/json")

    resp, err := client.Do(req)
    if err != nil {
        fmt.Println(err)
        return
    }
    defer resp.Body.Close()

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println(string(body))
}
```

```jsonnet .NET theme={null}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY");
            client.DefaultRequestHeaders.Add("x-workspace-id", "YOUR_WORKSPACE_ID");
            var content = new StringContent(@"{
  ""base_version"": 1,
  ""operations"": [
    {
      ""op"": ""replace"",
      ""old"": ""$1.2M"",
      ""new"": ""$1.4M""
    }
  ]
}", Encoding.UTF8, "application/json");

            var response = await client.PostAsync("https://api.tess.im/artifacts/artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f/edit", content);
            string responseBody = await response.Content.ReadAsStringAsync();
            Console.WriteLine(responseBody);
        }
    }
}
```

```ruby Ruby theme={null}
require 'uri'
require 'net/http'
require 'json'

uri = URI('https://api.tess.im/artifacts/artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f/edit')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer YOUR_API_KEY'
request['x-workspace-id'] = 'YOUR_WORKSPACE_ID'
request['Content-Type'] = 'application/json'
request.body = { 'base_version' => 1, 'operations' => [{ 'op' => 'replace', 'old' => '$1.2M', 'new' => '$1.4M' }] }.to_json

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

### **Path Parameters**

**universal\_id** `string` *required*

The artifact ID (`universal_id`), for example `artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f`.

### **Headers**

**x-workspace-id** `integer` *required*

Workspace ID. **Required as of 2026-09-01.** Until then, if omitted, the user's selected workspace is used (deprecated). After the cutoff, a missing header returns **422**.

### **Request Body**

**base\_version** `integer`

Version the edit is based on (minimum 1). If the latest version is newer, the call fails with 409.

**operations** `object[]` *required*

One or more operations (at most 40). Each has `op`: `replace` (`old`, `new`), `insert_before` / `insert_after` (`anchor`, `text`), `replace_range` (`from`, `to`, `new`), `prepend` / `append` (`text`), `set_text` (`selector`, `text`), `replace_element` (`selector`, `html`), `set_attribute` (`selector`, `name`, `value`) or `remove_element` (`selector`). Selector operations target one element of the content region.

### **Response**

**200**

```json theme={null}
{
  "universal_id": "artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f",
  "version": 2,
  "title": "Weekly pipeline",
  "viewer_url": "https://tess.im/artifacts/artifact_5d1f0c2e-8a3b-4c6d-9e7f-1a2b3c4d5e6f"
}
```

### **Response fields**

**universal\_id** `string`

The artifact ID.

**version** `integer`

The new version number.

**title** `string`

Title.

**viewer\_url** `string`

Link that opens the artifact in Tess.

### **Errors**

| Status | Meaning |
| - | - |
| `401` | Missing or invalid API token. |
| `403` | `ARTIFACT_EDIT_FORBIDDEN`: you can read the artifact but you are not its owner. Also `ARTIFACT_FEATURE_DISABLED`, `ARTIFACT_PLAN_NOT_ALLOWED` or `ARTIFACT_ROLE_NOT_ALLOWED` when the feature, plan or role does not allow artifacts. |
| `404` | `ARTIFACT_NOT_FOUND`: the artifact does not exist or is not yours. |
| `409` | `ARTIFACT_STALE`: the latest version is newer than `base_version`. Read the artifact again and redo the edit. |
| `422` | Validation error, `ARTIFACT_EXTERNAL_RESOURCE`, or an operation error: `ARTIFACT_ANCHOR_NOT_FOUND`, `ARTIFACT_ANCHOR_AMBIGUOUS`, `ARTIFACT_SELECTOR_NOT_FOUND`, `ARTIFACT_SELECTOR_AMBIGUOUS`, `ARTIFACT_SELECTOR_INVALID`, `ARTIFACT_TOO_MANY_OPERATIONS`, `ARTIFACT_PATCH_TOO_LARGE`, `ARTIFACT_CONTENT_TOO_LARGE`, `ARTIFACT_INVALID_OPERATION`. |
| `429` | Too many requests. Retry after a short wait. |

**409**

```json theme={null}
{
  "error_code": "ARTIFACT_STALE",
  "message": "Artifact is at version 2, edit was based on 1."
}
```


## OpenAPI

````yaml api-reference/tess-public-api.openapi.json POST /artifacts/{universal_id}/edit
openapi: 3.0.0
info:
  title: Tess API
  version: '0.1'
servers:
  - url: https://api.tess.im
security: []
paths:
  /artifacts/{universal_id}/edit:
    post:
      tags:
        - Artifacts
      summary: Edit an artifact
      description: >-
        Applies patch operations to the head and writes a new version.
        Operations: `replace` (old, new), `insert_before`/`insert_after`
        (anchor, text), `replace_range` (from, to, new), `prepend`/`append`
        (text), and selector operations on one element of the content region:
        `set_text` (selector, text), `replace_element` (selector, html),
        `set_attribute` (selector, name, value), `remove_element` (selector).
        Anchors and selectors must match exactly once. Send `base_version` to
        get 409 ARTIFACT_STALE instead of editing a newer head.
      operationId: 786a8a4cbfa1ff77d636bcde57098d98
      parameters:
        - name: universal_id
          in: path
          required: true
          schema:
            type: string
        - name: x-workspace-id
          in: header
          description: >-
            Workspace id. If not provided, the user's selected workspace is
            used.
          required: false
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              required:
                - operations
              properties:
                base_version:
                  type: integer
                  minimum: 1
                  nullable: true
                operations:
                  type: array
                  items:
                    required:
                      - op
                    properties:
                      op:
                        type: string
                        enum:
                          - replace
                          - insert_before
                          - insert_after
                          - replace_range
                          - prepend
                          - append
                          - set_text
                          - replace_element
                          - set_attribute
                          - remove_element
                      old:
                        type: string
                      new:
                        type: string
                      anchor:
                        type: string
                      text:
                        type: string
                      from:
                        type: string
                      to:
                        type: string
                      selector:
                        type: string
                        maxLength: 1000
                      html:
                        type: string
                      name:
                        type: string
                      value:
                        type: string
                    type: object
                  maxItems: 40
                  minItems: 1
              type: object
      responses:
        '200':
          description: New head version
          content:
            application/json:
              schema:
                properties:
                  universal_id:
                    type: string
                  version:
                    type: integer
                  title:
                    type: string
                  viewer_url:
                    type: string
                type: object
        '403':
          description: >-
            ARTIFACT_EDIT_FORBIDDEN (the caller can read the artifact but is not
            its owner), ARTIFACT_FEATURE_DISABLED, ARTIFACT_PLAN_NOT_ALLOWED or
            ARTIFACT_ROLE_NOT_ALLOWED
        '404':
          description: ARTIFACT_NOT_FOUND
        '409':
          description: ARTIFACT_STALE
        '422':
          description: >-
            Validation error or an ARTIFACT_* operation error (anchor/selector
            not found or ambiguous, too many operations, patch or content too
            large)
        '429':
          description: Too many requests
      security:
        - token: []
components:
  securitySchemes:
    token:
      type: http
      bearerFormat: Bearer
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.