# Groups

Group management

## Fetch a list of Groups

`GET /groups`

Without any params, returns a list of the Groups the user belongs to

Authentication (security requirement alternatives):

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

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

Parameters:

- `all` (query, boolean, optional) - Can only be used by admins or managers to fetch all entities
  Type: boolean

- `userId` (query, integer, optional) - Standard users can use this only with their own _userId_
  Type: integer

- `limit` (query, integer, optional) - Limit the number of returned results
  Type: integer

- `offset` (query, integer, optional) - Offset for pagination
  Type: integer

- `keyword` (query, string, optional) - Search keyword filter
  Type: string

Responses:

- 200: OK

Content type: application/json

Type: Array<Group>

Items:
  Reference: [Group](https://sourcey-traccar.pages.dev/api-reference/models/group/index.md); Type: Group

- 401: Unauthorized

## Examples

### cURL

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

### JavaScript

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

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

### Python

```python
import requests

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


## Create a Group

`POST /groups`

Authentication (security requirement alternatives):

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

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

Request body: application/json (required)

Type: Group

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

- `id` (optional)
  Type: integer, int64
  
  Unique group identifier

- `name` (optional)
  Type: string
  
  Group display name

- `groupId` (optional)
  Type: integer, int64
  
  Parent group identifier for nested grouping

- `attributes` (optional)
  Type: object
  
  Arbitrary metadata attached to the group

Responses:

- 200: OK

Content type: application/json

Type: Group

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

- `id` (optional)
  Type: integer, int64
  
  Unique group identifier

- `name` (optional)
  Type: string
  
  Group display name

- `groupId` (optional)
  Type: integer, int64
  
  Parent group identifier for nested grouping

- `attributes` (optional)
  Type: object
  
  Arbitrary metadata attached to the group

- 400: No permission

## Examples

### cURL

```bash
curl -X POST 'https://demo.traccar.org/api/groups' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "id": 0,
  "name": "string",
  "groupId": 0,
  "attributes": {}
}'
```

### JavaScript

```javascript
const body = `{
  "id": 0,
  "name": "string",
  "groupId": 0,
  "attributes": {}
}`;

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

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

### Python

```python
import requests

body = '''{
  "id": 0,
  "name": "string",
  "groupId": 0,
  "attributes": {}
}'''

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


## Fetch a Group

`GET /groups/{id}`

Authentication (security requirement alternatives):

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

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

Parameters:

- `id` (path, integer, required)
  Type: integer

Responses:

- 200: OK

Content type: application/json

Type: Group

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

- `id` (optional)
  Type: integer, int64
  
  Unique group identifier

- `name` (optional)
  Type: string
  
  Group display name

- `groupId` (optional)
  Type: integer, int64
  
  Parent group identifier for nested grouping

- `attributes` (optional)
  Type: object
  
  Arbitrary metadata attached to the group

- 401: Unauthorized

- 404: Not found

## Examples

### cURL

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

### JavaScript

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

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

### Python

```python
import requests

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


## Update a Group

`PUT /groups/{id}`

Authentication (security requirement alternatives):

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

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

Parameters:

- `id` (path, integer, required)
  Type: integer

Request body: application/json (required)

Type: Group

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

- `id` (optional)
  Type: integer, int64
  
  Unique group identifier

- `name` (optional)
  Type: string
  
  Group display name

- `groupId` (optional)
  Type: integer, int64
  
  Parent group identifier for nested grouping

- `attributes` (optional)
  Type: object
  
  Arbitrary metadata attached to the group

Responses:

- 200: OK

Content type: application/json

Type: Group

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

- `id` (optional)
  Type: integer, int64
  
  Unique group identifier

- `name` (optional)
  Type: string
  
  Group display name

- `groupId` (optional)
  Type: integer, int64
  
  Parent group identifier for nested grouping

- `attributes` (optional)
  Type: object
  
  Arbitrary metadata attached to the group

- 400: Bad request

- 401: Unauthorized

## Examples

### cURL

```bash
curl -X PUT 'https://demo.traccar.org/api/groups/0' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "id": 0,
  "name": "string",
  "groupId": 0,
  "attributes": {}
}'
```

### JavaScript

```javascript
const body = `{
  "id": 0,
  "name": "string",
  "groupId": 0,
  "attributes": {}
}`;

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

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

### Python

```python
import requests

body = '''{
  "id": 0,
  "name": "string",
  "groupId": 0,
  "attributes": {}
}'''

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


## Delete a Group

`DELETE /groups/{id}`

Authentication (security requirement alternatives):

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

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

Parameters:

- `id` (path, integer, required)
  Type: integer

Responses:

- 204: No Content

- 401: Unauthorized

## Examples

### cURL

```bash
curl -X DELETE 'https://demo.traccar.org/api/groups/0' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE'
```

### JavaScript

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

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

### Python

```python
import requests

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