# Instance Follows

Managing servers which the instance interacts with is crucial to the concept of federation in PeerTube and external video indexation. The PeerTube server then deals with inter-server ActivityPub operations and propagates information across its social graph by posting activities to actors' inbox endpoints.


## List instances following the server

`GET /api/v1/server/followers`

Authentication: no security requirement declared for this operation.

Parameters:

- `state` (query, string, optional)
  Type: string
  
  enum: ["pending","accepted"]

- `actorType` (query, string, optional)
  Type: string
  
  enum: ["Person","Application","Group","Service","Organization"]

- `start` (query, integer, optional) - Offset used to paginate results
  Type: integer
  
  minimum: 0

- `count` (query, integer, optional) - Number of items to return
  Type: integer
  
  default: 15
  
  minimum: 1
  
  maximum: 100

- `sort` (query, string, optional) - Sort column
  Type: string
  
  Example:
  
  ```json
  "-createdAt"
  ```

Responses:

- 200: successful operation

Content type: application/json

Type: object

- `total` (optional)
  Type: integer
  
  Example:
  
  ```json
  1
  ```

- `data` (optional)
  Type: Array<Follow>
  
  Items:
    Reference: [Follow](https://docs.joinpeertube.org/api-rest-reference/api/models/follow.md); Type: Follow

## Examples

### cURL

```bash
curl -X GET 'https://peertube2.cpy.re/api/v1/server/followers?count=15'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/server/followers?count=15', {
  method: 'GET',
});

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

### Python

```python
import requests

response = requests.get('https://peertube2.cpy.re/api/v1/server/followers?count=15')
print(response.text)
```


## Remove or reject a follower to your server

`DELETE /api/v1/server/followers/{handle}`

Authentication (security requirement alternatives):

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

- 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: admin

Parameters:

- `handle` (path, string, email, required) - The remote actor handle to remove from your followers
  Type: string, email

Responses:

- 204: successful operation

- 404: follower not found

## Examples

### cURL

```bash
curl -X DELETE 'https://peertube2.cpy.re/api/v1/server/followers/user%40example.com' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/server/followers/user%40example.com', {
  method: 'DELETE',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

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

### Python

```python
import requests

response = requests.delete(
    'https://peertube2.cpy.re/api/v1/server/followers/user%40example.com',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```


## Reject a pending follower to your server

`POST /api/v1/server/followers/{handle}/reject`

Authentication (security requirement alternatives):

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

- 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: admin

Parameters:

- `handle` (path, string, email, required) - The remote actor handle to remove from your followers
  Type: string, email

Responses:

- 204: successful operation

- 404: follower not found

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/server/followers/user%40example.com/reject' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/server/followers/user%40example.com/reject', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

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

### Python

```python
import requests

response = requests.post(
    'https://peertube2.cpy.re/api/v1/server/followers/user%40example.com/reject',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```


## Accept a pending follower to your server

`POST /api/v1/server/followers/{handle}/accept`

Authentication (security requirement alternatives):

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

- 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: admin

Parameters:

- `handle` (path, string, email, required) - The remote actor handle to remove from your followers
  Type: string, email

Responses:

- 204: successful operation

- 404: follower not found

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/server/followers/user%40example.com/accept' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/server/followers/user%40example.com/accept', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

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

### Python

```python
import requests

response = requests.post(
    'https://peertube2.cpy.re/api/v1/server/followers/user%40example.com/accept',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```


## List instances followed by the server

`GET /api/v1/server/following`

Authentication: no security requirement declared for this operation.

Parameters:

- `state` (query, string, optional)
  Type: string
  
  enum: ["pending","accepted"]

- `actorType` (query, string, optional)
  Type: string
  
  enum: ["Person","Application","Group","Service","Organization"]

- `start` (query, integer, optional) - Offset used to paginate results
  Type: integer
  
  minimum: 0

- `count` (query, integer, optional) - Number of items to return
  Type: integer
  
  default: 15
  
  minimum: 1
  
  maximum: 100

- `sort` (query, string, optional) - Sort column
  Type: string
  
  Example:
  
  ```json
  "-createdAt"
  ```

Responses:

- 200: successful operation

Content type: application/json

Type: object

- `total` (optional)
  Type: integer
  
  Example:
  
  ```json
  1
  ```

- `data` (optional)
  Type: Array<Follow>
  
  Items:
    Reference: [Follow](https://docs.joinpeertube.org/api-rest-reference/api/models/follow.md); Type: Follow

## Examples

### cURL

```bash
curl -X GET 'https://peertube2.cpy.re/api/v1/server/following?count=15'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/server/following?count=15', {
  method: 'GET',
});

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

### Python

```python
import requests

response = requests.get('https://peertube2.cpy.re/api/v1/server/following?count=15')
print(response.text)
```


## Follow a list of actors (PeerTube instance, channel or account)

`POST /api/v1/server/following`

Authentication (security requirement alternatives):

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

- 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: admin

Request body: application/json

Type: object

- `hosts` (optional)
  Type: Array<string>
  
  uniqueItems: true
  
  Items:
    Type: string, hostname

- `handles` (optional)
  Type: Array<string>
  
  uniqueItems: true
  
  Items:
    Type: string

Responses:

- 204: successful operation

- 500: cannot follow a non-HTTPS server

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/server/following' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "hosts": [
    "example.com"
  ],
  "handles": [
    "string"
  ]
}'
```

### JavaScript

```javascript
const body = `{
  "hosts": [
    "example.com"
  ],
  "handles": [
    "string"
  ]
}`;

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

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

### Python

```python
import requests

body = '''{
  "hosts": [
    "example.com"
  ],
  "handles": [
    "string"
  ]
}'''

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


## Unfollow an actor (PeerTube instance, channel or account)

`DELETE /api/v1/server/following/{hostOrHandle}`

Authentication (security requirement alternatives):

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

- 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: admin

Parameters:

- `hostOrHandle` (path, string, required) - The hostOrHandle to unfollow
  Type: string

Responses:

- 204: successful operation

- 404: host or handle not found

## Examples

### cURL

```bash
curl -X DELETE 'https://peertube2.cpy.re/api/v1/server/following/string' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/server/following/string', {
  method: 'DELETE',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

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

### Python

```python
import requests

response = requests.delete(
    'https://peertube2.cpy.re/api/v1/server/following/string',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```
