# Video Embed Privacy

## Get video embed privacy

`GET /api/v1/videos/{id}/embed-privacy`

**PeerTube >= 8.1**

Authentication (security requirement alternatives):

```json
[
  {
    "OAuth2": [
      "user"
    ]
  }
]
```

- OAuth2: oauth2. Authenticating via OAuth requires the following steps:
- Have an activated account
- [Generate] an access token for that account at `/api/v1/users/token`.
- Make requests with the *Authorization: Bearer <token\>* header
- Profit, depending on the role assigned to the account

Note that the __access token is valid for 1 day__ and is given
along with a __refresh token valid for 2 weeks__.

[Generate]: https://docs.joinpeertube.org/api/rest-getting-started
; scopes: user

Parameters:

- `id` (path, id | UUIDv4 | shortUUID, required) - The object id, uuid or short uuid
  Type: id | UUIDv4 | shortUUID
  
  oneOf:
    Reference: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md); Type: id
    
    minimum: 1
    
    Example:
    
    ```json
    42
    ```
  
    Reference: [UUIDv4](https://docs.joinpeertube.org/api-rest-reference/api/models/uuidv4.md); Type: UUIDv4, uuid
    
    minLength: 36
    
    maxLength: 36
    
    pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    
    Example:
    
    ```json
    "9c9de5e8-0a1e-484a-b099-e80766180a6d"
    ```
  
    Reference: [shortUUID](https://docs.joinpeertube.org/api-rest-reference/api/models/shortuuid.md); Type: shortUUID
    
    translation of a uuid v4 with a bigger alphabet to have a shorter uuid
    
    Example:
    
    ```json
    "2y84q2MQUMWPbiEcxNXMgC"
    ```

Responses:

- 200: successful operation

Content type: application/json

Type: object

- `policy` (optional)
  Type: object
  
  - `id` (optional)
    Reference: [VideoEmbedPrivacy](https://docs.joinpeertube.org/api-rest-reference/api/models/videoembedprivacy.md); Type: VideoEmbedPrivacy
    
    The video embed privacy level:
      - `1` All allowed: anyone can embed the video
      - `2` Allowlist: only the domains in the allowlist can embed the video
      - `3` Remote restrictions: the remote instance has restrictions on where the video can be embedded
      - `4` Nobody can embed this video
    
    
    enum: [1,2,3,4]
  
  - `label` (optional)
    Type: string
    
    Example:
    
    ```json
    "Allowlist"
    ```

- `domains` (optional)
  Type: Array<string>
  
  Items:
    Type: string
    
    Example:
    
    ```json
    "example.com"
    ```

- 400: invalid request

## Examples

### cURL

```bash
curl -X GET 'https://peertube2.cpy.re/api/v1/videos/42/embed-privacy' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/videos/42/embed-privacy', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

const data = await response.text();
```

### Python

```python
import requests

response = requests.get(
    'https://peertube2.cpy.re/api/v1/videos/42/embed-privacy',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```


## Update video embed privacy

`PUT /api/v1/videos/{id}/embed-privacy`

**PeerTube >= 8.1**

Authentication (security requirement alternatives):

```json
[
  {
    "OAuth2": [
      "user"
    ]
  }
]
```

- OAuth2: oauth2. Authenticating via OAuth requires the following steps:
- Have an activated account
- [Generate] an access token for that account at `/api/v1/users/token`.
- Make requests with the *Authorization: Bearer <token\>* header
- Profit, depending on the role assigned to the account

Note that the __access token is valid for 1 day__ and is given
along with a __refresh token valid for 2 weeks__.

[Generate]: https://docs.joinpeertube.org/api/rest-getting-started
; scopes: user

Parameters:

- `id` (path, id | UUIDv4 | shortUUID, required) - The object id, uuid or short uuid
  Type: id | UUIDv4 | shortUUID
  
  oneOf:
    Reference: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md); Type: id
    
    minimum: 1
    
    Example:
    
    ```json
    42
    ```
  
    Reference: [UUIDv4](https://docs.joinpeertube.org/api-rest-reference/api/models/uuidv4.md); Type: UUIDv4, uuid
    
    minLength: 36
    
    maxLength: 36
    
    pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    
    Example:
    
    ```json
    "9c9de5e8-0a1e-484a-b099-e80766180a6d"
    ```
  
    Reference: [shortUUID](https://docs.joinpeertube.org/api-rest-reference/api/models/shortuuid.md); Type: shortUUID
    
    translation of a uuid v4 with a bigger alphabet to have a shorter uuid
    
    Example:
    
    ```json
    "2y84q2MQUMWPbiEcxNXMgC"
    ```

Request body: application/json

Type: object

- `policy` (optional)
  Reference: [VideoEmbedPrivacy](https://docs.joinpeertube.org/api-rest-reference/api/models/videoembedprivacy.md); Type: VideoEmbedPrivacy
  
  The video embed privacy level:
    - `1` All allowed: anyone can embed the video
    - `2` Allowlist: only the domains in the allowlist can embed the video
    - `3` Remote restrictions: the remote instance has restrictions on where the video can be embedded
    - `4` Nobody can embed this video
  
  
  enum: [1,2,3,4]

- `domains` (optional)
  Type: Array<string>
  
  Items:
    Type: string
    
    Example:
    
    ```json
    "example.com"
    ```

Responses:

- 204: successful operation

- 400: invalid request

## Examples

### cURL

```bash
curl -X PUT 'https://peertube2.cpy.re/api/v1/videos/42/embed-privacy' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "policy": 1,
  "domains": [
    "example.com"
  ]
}'
```

### JavaScript

```javascript
const body = `{
  "policy": 1,
  "domains": [
    "example.com"
  ]
}`;

const response = await fetch('https://peertube2.cpy.re/api/v1/videos/42/embed-privacy', {
  method: 'PUT',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "policy": 1,
  "domains": [
    "example.com"
  ]
}'''

response = requests.put(
    'https://peertube2.cpy.re/api/v1/videos/42/embed-privacy',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Check if embed is allowed

`GET /api/v1/videos/{id}/embed-privacy/allowed`

**PeerTube >= 8.1** Check if video embed is allowed on a specific domain according to the video embed privacy settings

Authentication (security requirement alternatives):

```json
[
  {
    "OAuth2": [
      "user"
    ]
  }
]
```

- OAuth2: oauth2. Authenticating via OAuth requires the following steps:
- Have an activated account
- [Generate] an access token for that account at `/api/v1/users/token`.
- Make requests with the *Authorization: Bearer <token\>* header
- Profit, depending on the role assigned to the account

Note that the __access token is valid for 1 day__ and is given
along with a __refresh token valid for 2 weeks__.

[Generate]: https://docs.joinpeertube.org/api/rest-getting-started
; scopes: user

Parameters:

- `id` (path, id | UUIDv4 | shortUUID, required) - The object id, uuid or short uuid
  Type: id | UUIDv4 | shortUUID
  
  oneOf:
    Reference: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md); Type: id
    
    minimum: 1
    
    Example:
    
    ```json
    42
    ```
  
    Reference: [UUIDv4](https://docs.joinpeertube.org/api-rest-reference/api/models/uuidv4.md); Type: UUIDv4, uuid
    
    minLength: 36
    
    maxLength: 36
    
    pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    
    Example:
    
    ```json
    "9c9de5e8-0a1e-484a-b099-e80766180a6d"
    ```
  
    Reference: [shortUUID](https://docs.joinpeertube.org/api-rest-reference/api/models/shortuuid.md); Type: shortUUID
    
    translation of a uuid v4 with a bigger alphabet to have a shorter uuid
    
    Example:
    
    ```json
    "2y84q2MQUMWPbiEcxNXMgC"
    ```

- `domain` (query, string, required) - The domain to check if embed is allowed
  Type: string

Responses:

- 200: successful operation

Content type: application/json

Type: object

- `domainAllowed` (optional)
  Type: boolean

- `userBypassAllowed` (optional)
  Type: boolean; nullable
  
  Whether the user can bypass embed restrictions for this video, either because they are the owner/editor of the video or because they have a moderator or admin role

- 400: invalid request

## Examples

### cURL

```bash
curl -X GET 'https://peertube2.cpy.re/api/v1/videos/42/embed-privacy/allowed?domain=string' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/videos/42/embed-privacy/allowed?domain=string', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

const data = await response.text();
```

### Python

```python
import requests

response = requests.get(
    'https://peertube2.cpy.re/api/v1/videos/42/embed-privacy/allowed?domain=string',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```
