# Replace, in one undoable batch, every clip that reads an earlier render of an animation with a new render of it

> POST /api/v1/projects/{id}/motion/replace: Replace, in one undoable batch, every clip that reads an earlier render of an animation with a new render of it

Source: https://stuarty.com/docs/api/projects.motion.replace/

## Authentication

Send the secret in the header `Authorization: Bearer <secret>`: the local token in local mode, an [API key](/docs/self-hosting/api-keys) in network mode. An API key needs the `edit` scope; the local token has every scope. See the [API overview](/docs/api/overview) for both modes.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | min length 1 |

## Request body

Content type `application/json`.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `asset_id` | `string` | yes | The new render: an asset of the timeline, ready.. min length 1 |
| `dry_run` | `boolean` | no |  |
| `render_key` | `string` | no | The key of the animation; default the render key of the origin of the new asset. |
| `timeline_id` | `string` | no | The timeline of the project; required when the project has several. |

## Responses

### 200 OK

Content type `application/json`. Schema: [`MotionReplaceResult`](/docs/api/schemas#motionreplaceresult).

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `actor` | `string` | no |  |
| `applied` | `boolean` | no |  |
| `asset_id` | `string` | no |  |
| `base_revision` | `integer (int64)` | no |  |
| `created` | array of `string` | no |  |
| `description` | `string` | no |  |
| `diff` | array of [`Change`](/docs/api/schemas#change) | no |  |
| `dry_run` | `boolean` | no |  |
| `effective` | array of [`OpEffect`](/docs/api/schemas#opeffect) | no |  |
| `findings` | array of [`Finding`](/docs/api/schemas#finding) | no |  |
| `lint` | [`LintTotals`](/docs/api/schemas#linttotals) | no |  |
| `project_id` | `string` | no |  |
| `render_key` | `string` | no |  |
| `replaced` | array of `string` | no |  |
| `replayed` | `boolean` | no |  |
| `revision` | `integer (int64)` | no |  |
| `untrusted_notice` | `string` | no |  |

### 400

Validation failed; errors maps each field to its messages and issues lists each problem with its code, key and params

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### 401 Unauthorized

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### 403

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### 404

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### 409

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### 422 Unprocessable Content

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### 429

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

### Any other status

Error (RFC 9457 problem details)

Content type `application/problem+json`. Schema: [`Problem`](/docs/api/schemas#problem).

```bash
curl -X POST "http://127.0.0.1:7878/api/v1/projects/PROJECT_ID/motion/replace" \
  -H "Authorization: Bearer $STUARTY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "asset_id": "string"
}'
```

```python
import os

import requests

response = requests.post(
    "http://127.0.0.1:7878/api/v1/projects/PROJECT_ID/motion/replace",
    headers={"Authorization": f"Bearer {os.environ['STUARTY_KEY']}"},
    json={
        "asset_id": "string",
    },
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

```javascript
const response = await fetch("http://127.0.0.1:7878/api/v1/projects/PROJECT_ID/motion/replace", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.STUARTY_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "asset_id": "string"
  }),
});
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
console.log(await response.json());
```

```go
package main

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

func main() {
	body := strings.NewReader(`{
  "asset_id": "string"
}`)
	url := "http://127.0.0.1:7878/api/v1/projects/PROJECT_ID/motion/replace"
	req, err := http.NewRequest("POST", url, body)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("STUARTY_KEY"))
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	out, err := io.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Status, string(out))
}
```

```php
<?php

$ch = curl_init("http://127.0.0.1:7878/api/v1/projects/PROJECT_ID/motion/replace");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("STUARTY_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => '{
  "asset_id": "string"
}',
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new RuntimeException(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $response, PHP_EOL;
```

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("http://127.0.0.1:7878/api/v1/projects/PROJECT_ID/motion/replace"))
            .header("Authorization", "Bearer " + System.getenv("STUARTY_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString("""
                {
                  "asset_id": "string"
                }
                """))
            .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
            .send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}
```

```csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

using var client = new HttpClient();
using var request = new HttpRequestMessage(
    HttpMethod.Post, "http://127.0.0.1:7878/api/v1/projects/PROJECT_ID/motion/replace");
request.Headers.Authorization = new AuthenticationHeaderValue(
    "Bearer", Environment.GetEnvironmentVariable("STUARTY_KEY"));
request.Content = new StringContent("""
{
  "asset_id": "string"
}
""", Encoding.UTF8, "application/json");

using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

```ruby
require "net/http"
require "uri"

uri = URI("http://127.0.0.1:7878/api/v1/projects/PROJECT_ID/motion/replace")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch('STUARTY_KEY')}"
request["Content-Type"] = "application/json"
request.body = '{
  "asset_id": "string"
}'

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end
puts "#{response.code} #{response.body}"
```

**Response examples**

```json
{
  "actor": "string",
  "applied": false,
  "asset_id": "string",
  "base_revision": 0,
  "created": [
    "string"
  ],
  "description": "string",
  "diff": [
    {
      "changes": {},
      "id": "string",
      "kind": "string",
      "object": {}
    }
  ],
  "dry_run": false,
  "effective": [
    {
      "created": [],
      "effective": {},
      "index": 0,
      "op": "string"
    }
  ],
  "findings": [
    {
      "code": "string",
      "hint": "string",
      "item": "string",
      "message": "string",
      "range": {},
      "severity": "string"
    }
  ],
  "lint": {
    "errors": 0,
    "lint_scope": "string",
    "warnings": 0
  },
  "project_id": "string",
  "render_key": "string",
  "replaced": [
    "string"
  ],
  "replayed": false,
  "revision": 0,
  "untrusted_notice": "string"
}
```

```json
{
  "code": "string",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "string",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "string",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 0,
  "title": "string",
  "type": "string"
}
```

```json
{
  "code": "E_UNAUTHORIZED",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "send the local token as Authorization: Bearer <token>, or run `stuarty open` to open the editor in a browser",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "the request carries no credentials.",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 401,
  "title": "string",
  "type": "string"
}
```

```json
{
  "code": "string",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "string",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "string",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 0,
  "title": "string",
  "type": "string"
}
```

```json
{
  "code": "string",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "string",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "string",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 0,
  "title": "string",
  "type": "string"
}
```

```json
{
  "code": "string",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "string",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "string",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 0,
  "title": "string",
  "type": "string"
}
```

```json
{
  "code": "E_VALIDATION",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "string",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "string",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 422,
  "title": "string",
  "type": "string"
}
```

```json
{
  "code": "string",
  "detail": "string",
  "details": {},
  "errors": {},
  "hint": "string",
  "instance": "string",
  "issues": [
    {
      "code": "string",
      "key": "string",
      "message": "string",
      "on": "string",
      "params": {},
      "path": "string"
    }
  ],
  "message": "string",
  "op_index": 0,
  "path": "string",
  "request_id": "string",
  "retryable": false,
  "status": 0,
  "title": "string",
  "type": "string"
}
```

The examples are built from the schemas of the OpenAPI document, so a value is a placeholder of its type. The fields that carry the real values are in the tables.
