# Prepare a recording: store its source, tracks, script and notes so that a person only presses record (starts nothing)

> POST /api/v1/recordings/prepare: Prepare a recording: store its source, tracks, script and notes so that a person only presses record (starts nothing)

Source: https://stuarty.com/docs/api/recordings.prepare/

## 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 `media` scope; the local token has every scope. See the [API overview](/docs/api/overview) for both modes.

## Request body

Content type `application/json`.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `camera` | `string` | no | A camera id from GET /recording/sources; empty records no camera. |
| `events` | `boolean` | no | Save the pointer position and the clicks (never a key) beside the recording. |
| `fps` | `integer` | no | 24, 30 (the default) or 60. |
| `microphone` | `string` | no | A microphone id from GET /recording/sources, or default; empty records no microphone. |
| `notes` | `string` | no | A note for the person who presses record; at most 2000 characters, plain text. |
| `project_id` | `string` | yes | The project the recording will join once a person adds it.. min length 1 |
| `script_id` | `string` | no | A script of the project (a text item of kind script) the person will read. |
| `source` | [`recordingSourceIn`](/docs/api/schemas#recordingsourcein) | yes |  |
| `system_audio` | `boolean` | no | Record the sound the computer plays on a track of its own. |

## Responses

### 200 OK

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

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `actor` | `string` | no |  |
| `asset_id` | `string` | no |  |
| `bytes` | `integer (int64)` | no |  |
| `created_at` | `string (date-time)` | no |  |
| `dropped` | `integer (int64)` | no |  |
| `duration_ms` | `integer (int64)` | no |  |
| `encoder` | `string` | no |  |
| `ended_at` | `string (date-time)` or `null` | no |  |
| `error` | [`Error`](/docs/api/schemas#error) or `any` or `null` or `null` | no |  |
| `events_count` | `integer (int64)` | no |  |
| `fps` | `integer` | no |  |
| `frames` | `integer (int64)` | no |  |
| `height` | `integer` | no |  |
| `levels` | [`RecordingLevels`](/docs/api/schemas#recordinglevels) or `any` or `null` or `null` | no |  |
| `marks` | array of [`RecordingMark`](/docs/api/schemas#recordingmark) | no |  |
| `pauses` | array of [`RecordingPause`](/docs/api/schemas#recordingpause) | no |  |
| `plan` | [`RecordingPlan`](/docs/api/schemas#recordingplan) or `any` or `null` or `null` | no |  |
| `project_id` | `string` | no |  |
| `proposals` | array of [`RecordingProposal`](/docs/api/schemas#recordingproposal) | no |  |
| `recording_id` | `string` | no |  |
| `review` | `string` | no |  |
| `source` | [`RecordingSource`](/docs/api/schemas#recordingsource) | no |  |
| `started_at` | `string (date-time)` or `null` | no |  |
| `state` | `string` | no |  |
| `stop_reason` | `string` | no |  |
| `text` | `string` | no |  |
| `tracks` | array of [`RecordingTrack`](/docs/api/schemas#recordingtrack) | no |  |
| `upload` | [`RecordingUpload`](/docs/api/schemas#recordingupload) or `any` or `null` or `null` | no |  |
| `width` | `integer` | 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).

### 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/recordings/prepare" \
  -H "Authorization: Bearer $STUARTY_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "project_id": "string",
  "source": {
    "id": "string",
    "kind": "string",
    "name": "string"
  }
}'
```

```python
import os

import requests

response = requests.post(
    "http://127.0.0.1:7878/api/v1/recordings/prepare",
    headers={"Authorization": f"Bearer {os.environ['STUARTY_KEY']}"},
    json={
        "project_id": "string",
        "source": {
            "id": "string",
            "kind": "string",
            "name": "string",
        },
    },
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

```javascript
const response = await fetch("http://127.0.0.1:7878/api/v1/recordings/prepare", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.STUARTY_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "project_id": "string",
    "source": {
      "id": "string",
      "kind": "string",
      "name": "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(`{
  "project_id": "string",
  "source": {
    "id": "string",
    "kind": "string",
    "name": "string"
  }
}`)
	req, err := http.NewRequest("POST", "http://127.0.0.1:7878/api/v1/recordings/prepare", 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/recordings/prepare");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("STUARTY_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => '{
  "project_id": "string",
  "source": {
    "id": "string",
    "kind": "string",
    "name": "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/recordings/prepare"))
            .header("Authorization", "Bearer " + System.getenv("STUARTY_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString("""
                {
                  "project_id": "string",
                  "source": {
                    "id": "string",
                    "kind": "string",
                    "name": "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/recordings/prepare");
request.Headers.Authorization = new AuthenticationHeaderValue(
    "Bearer", Environment.GetEnvironmentVariable("STUARTY_KEY"));
request.Content = new StringContent("""
{
  "project_id": "string",
  "source": {
    "id": "string",
    "kind": "string",
    "name": "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/recordings/prepare")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch('STUARTY_KEY')}"
request["Content-Type"] = "application/json"
request.body = '{
  "project_id": "string",
  "source": {
    "id": "string",
    "kind": "string",
    "name": "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",
  "asset_id": "string",
  "bytes": 0,
  "created_at": "2006-01-02T15:04:05Z",
  "dropped": 0,
  "duration_ms": 0,
  "encoder": "string",
  "ended_at": "2006-01-02T15:04:05Z",
  "error": {
    "code": "string",
    "details": {},
    "hint": "string",
    "message": "string",
    "op_index": 0,
    "path": "string",
    "retryable": false
  },
  "events_count": 0,
  "fps": 0,
  "frames": 0,
  "height": 0,
  "levels": {
    "microphone": 0,
    "system": 0
  },
  "marks": [
    {
      "actor": "string",
      "at_ms": 0,
      "created_at": "2006-01-02T15:04:05Z",
      "end_ms": 0,
      "kind": "string",
      "n": 0,
      "note": "string"
    }
  ],
  "pauses": [
    {
      "from_ms": 0,
      "to_ms": 0
    }
  ],
  "plan": {
    "camera": "string",
    "events": false,
    "fps": 0,
    "microphone": "string",
    "notes": "string",
    "script_id": "string",
    "source_id": "string",
    "system_audio": false
  },
  "project_id": "string",
  "proposals": [
    {
      "actor": "string",
      "created_at": "2006-01-02T15:04:05Z",
      "decided_at": "2006-01-02T15:04:05Z",
      "decided_by": "string",
      "proposal_id": "string",
      "ranges": [],
      "revision": 0,
      "state": "string"
    }
  ],
  "recording_id": "string",
  "review": "string",
  "source": {
    "id": "string",
    "kind": "string",
    "name": "string"
  },
  "started_at": "2006-01-02T15:04:05Z",
  "state": "string",
  "stop_reason": "string",
  "text": "string",
  "tracks": [
    {
      "asset_id": "string",
      "bytes": 0,
      "duration_ms": 0,
      "kind": "string",
      "lost": false,
      "start_ms": 0
    }
  ],
  "upload": {
    "container": "string",
    "max_chunk_bytes": 0,
    "tracks": [
      {}
    ]
  },
  "width": 0
}
```

```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": "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.
