# Permissions

User permissions and other object linking

## Fetch permission links between Objects

`GET /permissions`

Provide exactly two `*Id` query parameters matching the Permission body shape (e.g. `reportId` and `deviceId`). Use `0` on a side to mean "any", e.g. `?reportId=5&deviceId=0` lists all devices linked to report 5. At least one side must be non-zero.

Authentication (security requirement alternatives):

```json
[
  {
    "BasicAuth": []
  },
  {
    "ApiKey": []
  }
]
```

- BasicAuth: http (basic)
- ApiKey: http (bearer)

Responses:

- 200: OK

Content type: application/json

Type: Array<Permission>

Items:
  Reference: [Permission](https://sourcey-traccar.pages.dev/api-reference/models/permission/index.md); Type: Permission
  
  This is a permission map that contain two object indexes. It is used to link/unlink objects. Order is important. Example: { deviceId:8, geofenceId: 16 }

- 400: Bad request

## Examples

### cURL

```bash
curl -X GET 'https://demo.traccar.org/api/permissions' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE'
```

### JavaScript

```javascript
const response = await fetch('https://demo.traccar.org/api/permissions', {
  method: 'GET',
  headers: {
    'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
  },
});

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

### Python

```python
import requests

response = requests.get(
    'https://demo.traccar.org/api/permissions',
    headers={
        'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
    },
)
print(response.text)
```


## Link an Object to another Object

`POST /permissions`

Authentication (security requirement alternatives):

```json
[
  {
    "BasicAuth": []
  },
  {
    "ApiKey": []
  }
]
```

- BasicAuth: http (basic)
- ApiKey: http (bearer)

Request body: application/json (required)

Type: Permission

This is a permission map that contain two object indexes. It is used to link/unlink objects. Order is important. Example: { deviceId:8, geofenceId: 16 }

Schema: [Permission](https://sourcey-traccar.pages.dev/api-reference/models/permission/index.md)

- `userId` (optional)
  Type: integer, int64
  
  User id, can be only first parameter

- `deviceId` (optional)
  Type: integer, int64
  
  Device id, can be first parameter or second only in combination with userId

- `groupId` (optional)
  Type: integer, int64
  
  Group id, can be first parameter or second only in combination with userId

- `geofenceId` (optional)
  Type: integer, int64
  
  Geofence id, can be second parameter only

- `notificationId` (optional)
  Type: integer, int64
  
  Notification id, can be second parameter only

- `calendarId` (optional)
  Type: integer, int64
  
  Calendar id, can be second parameter only and only in combination with userId

- `attributeId` (optional)
  Type: integer, int64
  
  Computed attribute id, can be second parameter only

- `driverId` (optional)
  Type: integer, int64
  
  Driver id, can be second parameter only

- `managedUserId` (optional)
  Type: integer, int64
  
  User id, can be second parameter only and only in combination with userId

- `commandId` (optional)
  Type: integer, int64
  
  Saved command id, can be second parameter only

Responses:

- 204: No Content

- 400: No permission

## Examples

### cURL

```bash
curl -X POST 'https://demo.traccar.org/api/permissions' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "userId": 0,
  "deviceId": 0,
  "groupId": 0,
  "geofenceId": 0,
  "notificationId": 0,
  "calendarId": 0,
  "attributeId": 0,
  "driverId": 0,
  "managedUserId": 0,
  "commandId": 0
}'
```

### JavaScript

```javascript
const body = `{
  "userId": 0,
  "deviceId": 0,
  "groupId": 0,
  "geofenceId": 0,
  "notificationId": 0,
  "calendarId": 0,
  "attributeId": 0,
  "driverId": 0,
  "managedUserId": 0,
  "commandId": 0
}`;

const response = await fetch('https://demo.traccar.org/api/permissions', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "userId": 0,
  "deviceId": 0,
  "groupId": 0,
  "geofenceId": 0,
  "notificationId": 0,
  "calendarId": 0,
  "attributeId": 0,
  "driverId": 0,
  "managedUserId": 0,
  "commandId": 0
}'''

response = requests.post(
    'https://demo.traccar.org/api/permissions',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Unlink an Object from another Object

`DELETE /permissions`

Authentication (security requirement alternatives):

```json
[
  {
    "BasicAuth": []
  },
  {
    "ApiKey": []
  }
]
```

- BasicAuth: http (basic)
- ApiKey: http (bearer)

Request body: application/json (required)

Type: Permission

This is a permission map that contain two object indexes. It is used to link/unlink objects. Order is important. Example: { deviceId:8, geofenceId: 16 }

Schema: [Permission](https://sourcey-traccar.pages.dev/api-reference/models/permission/index.md)

- `userId` (optional)
  Type: integer, int64
  
  User id, can be only first parameter

- `deviceId` (optional)
  Type: integer, int64
  
  Device id, can be first parameter or second only in combination with userId

- `groupId` (optional)
  Type: integer, int64
  
  Group id, can be first parameter or second only in combination with userId

- `geofenceId` (optional)
  Type: integer, int64
  
  Geofence id, can be second parameter only

- `notificationId` (optional)
  Type: integer, int64
  
  Notification id, can be second parameter only

- `calendarId` (optional)
  Type: integer, int64
  
  Calendar id, can be second parameter only and only in combination with userId

- `attributeId` (optional)
  Type: integer, int64
  
  Computed attribute id, can be second parameter only

- `driverId` (optional)
  Type: integer, int64
  
  Driver id, can be second parameter only

- `managedUserId` (optional)
  Type: integer, int64
  
  User id, can be second parameter only and only in combination with userId

- `commandId` (optional)
  Type: integer, int64
  
  Saved command id, can be second parameter only

Responses:

- 204: No Content

- 401: Unauthorized

## Examples

### cURL

```bash
curl -X DELETE 'https://demo.traccar.org/api/permissions' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "userId": 0,
  "deviceId": 0,
  "groupId": 0,
  "geofenceId": 0,
  "notificationId": 0,
  "calendarId": 0,
  "attributeId": 0,
  "driverId": 0,
  "managedUserId": 0,
  "commandId": 0
}'
```

### JavaScript

```javascript
const body = `{
  "userId": 0,
  "deviceId": 0,
  "groupId": 0,
  "geofenceId": 0,
  "notificationId": 0,
  "calendarId": 0,
  "attributeId": 0,
  "driverId": 0,
  "managedUserId": 0,
  "commandId": 0
}`;

const response = await fetch('https://demo.traccar.org/api/permissions', {
  method: 'DELETE',
  headers: {
    'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "userId": 0,
  "deviceId": 0,
  "groupId": 0,
  "geofenceId": 0,
  "notificationId": 0,
  "calendarId": 0,
  "attributeId": 0,
  "driverId": 0,
  "managedUserId": 0,
  "commandId": 0
}'''

response = requests.delete(
    'https://demo.traccar.org/api/permissions',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Link multiple Objects in a single request

`POST /permissions/bulk`

Authentication (security requirement alternatives):

```json
[
  {
    "BasicAuth": []
  },
  {
    "ApiKey": []
  }
]
```

- BasicAuth: http (basic)
- ApiKey: http (bearer)

Request body: application/json (required)

Type: Array<Permission>

Items:
  Reference: [Permission](https://sourcey-traccar.pages.dev/api-reference/models/permission/index.md); Type: Permission
  
  This is a permission map that contain two object indexes. It is used to link/unlink objects. Order is important. Example: { deviceId:8, geofenceId: 16 }

Responses:

- 204: No Content

- 400: Bad request

## Examples

### cURL

```bash
curl -X POST 'https://demo.traccar.org/api/permissions/bulk' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE' \
  -H 'Content-Type: application/json' \
  --data-raw '[
  {
    "userId": 0,
    "deviceId": 0,
    "groupId": 0,
    "geofenceId": 0,
    "notificationId": 0,
    "calendarId": 0,
    "attributeId": 0,
    "driverId": 0,
    "managedUserId": 0,
    "commandId": 0
  }
]'
```

### JavaScript

```javascript
const body = `[
  {
    "userId": 0,
    "deviceId": 0,
    "groupId": 0,
    "geofenceId": 0,
    "notificationId": 0,
    "calendarId": 0,
    "attributeId": 0,
    "driverId": 0,
    "managedUserId": 0,
    "commandId": 0
  }
]`;

const response = await fetch('https://demo.traccar.org/api/permissions/bulk', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''[
  {
    "userId": 0,
    "deviceId": 0,
    "groupId": 0,
    "geofenceId": 0,
    "notificationId": 0,
    "calendarId": 0,
    "attributeId": 0,
    "driverId": 0,
    "managedUserId": 0,
    "commandId": 0
  }
]'''

response = requests.post(
    'https://demo.traccar.org/api/permissions/bulk',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Unlink multiple Objects in a single request

`DELETE /permissions/bulk`

Authentication (security requirement alternatives):

```json
[
  {
    "BasicAuth": []
  },
  {
    "ApiKey": []
  }
]
```

- BasicAuth: http (basic)
- ApiKey: http (bearer)

Request body: application/json (required)

Type: Array<Permission>

Items:
  Reference: [Permission](https://sourcey-traccar.pages.dev/api-reference/models/permission/index.md); Type: Permission
  
  This is a permission map that contain two object indexes. It is used to link/unlink objects. Order is important. Example: { deviceId:8, geofenceId: 16 }

Responses:

- 204: No Content

- 400: Bad request

## Examples

### cURL

```bash
curl -X DELETE 'https://demo.traccar.org/api/permissions/bulk' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE' \
  -H 'Content-Type: application/json' \
  --data-raw '[
  {
    "userId": 0,
    "deviceId": 0,
    "groupId": 0,
    "geofenceId": 0,
    "notificationId": 0,
    "calendarId": 0,
    "attributeId": 0,
    "driverId": 0,
    "managedUserId": 0,
    "commandId": 0
  }
]'
```

### JavaScript

```javascript
const body = `[
  {
    "userId": 0,
    "deviceId": 0,
    "groupId": 0,
    "geofenceId": 0,
    "notificationId": 0,
    "calendarId": 0,
    "attributeId": 0,
    "driverId": 0,
    "managedUserId": 0,
    "commandId": 0
  }
]`;

const response = await fetch('https://demo.traccar.org/api/permissions/bulk', {
  method: 'DELETE',
  headers: {
    'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''[
  {
    "userId": 0,
    "deviceId": 0,
    "groupId": 0,
    "geofenceId": 0,
    "notificationId": 0,
    "calendarId": 0,
    "attributeId": 0,
    "driverId": 0,
    "managedUserId": 0,
    "commandId": 0
  }
]'''

response = requests.delete(
    'https://demo.traccar.org/api/permissions/bulk',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
