# Attributes

Computed attributes management

## Fetch a list of Attributes

`GET /attributes/computed`

Without params, it returns a list of Attributes the user has access 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

- `deviceId` (query, integer, optional) - Standard users can use this only with _deviceId_s, they have access to
  Type: integer

- `groupId` (query, integer, optional) - Standard users can use this only with _groupId_s, they have access to
  Type: integer

- `refresh` (query, boolean, optional)
  Type: boolean

- `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<Attribute>

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

- 401: Unauthorized

## Examples

### cURL

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

### JavaScript

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

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

### Python

```python
import requests

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


## Create an Attribute

`POST /attributes/computed`

Authentication (security requirement alternatives):

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

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

Request body: application/json (required)

Type: Attribute

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

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

- `description` (optional)
  Type: string
  
  Human readable name of the attribute

- `attribute` (optional)
  Type: string
  
  Attribute name used in expressions

- `expression` (optional)
  Type: string
  
  Expression that defines how the attribute is calculated

- `type` (optional)
  Type: string
  
  String|Number|Boolean

Responses:

- 200: OK

Content type: application/json

Type: Attribute

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

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

- `description` (optional)
  Type: string
  
  Human readable name of the attribute

- `attribute` (optional)
  Type: string
  
  Attribute name used in expressions

- `expression` (optional)
  Type: string
  
  Expression that defines how the attribute is calculated

- `type` (optional)
  Type: string
  
  String|Number|Boolean

- 400: Bad request

- 401: Unauthorized

## Examples

### cURL

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

### JavaScript

```javascript
const body = `{
  "id": 0,
  "description": "string",
  "attribute": "string",
  "expression": "string",
  "type": "string"
}`;

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

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

### Python

```python
import requests

body = '''{
  "id": 0,
  "description": "string",
  "attribute": "string",
  "expression": "string",
  "type": "string"
}'''

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


## Evaluate a Computed Attribute against the latest Device Position

`POST /attributes/computed/test`

Admin only. Returns the computed value without persisting the attribute.

Authentication (security requirement alternatives):

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

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

Parameters:

- `deviceId` (query, integer, required)
  Type: integer

Request body: application/json (required)

Type: Attribute

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

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

- `description` (optional)
  Type: string
  
  Human readable name of the attribute

- `attribute` (optional)
  Type: string
  
  Attribute name used in expressions

- `expression` (optional)
  Type: string
  
  Expression that defines how the attribute is calculated

- `type` (optional)
  Type: string
  
  String|Number|Boolean

Responses:

- 200: OK

Content type: application/json

Type: number | boolean | string

oneOf:
  Type: number

  Type: boolean

  Type: string

- 204: Computation produced no value

- 400: Bad request

- 401: Unauthorized

## Examples

### cURL

```bash
curl -X POST 'https://demo.traccar.org/api/attributes/computed/test?deviceId=0' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "id": 0,
  "description": "string",
  "attribute": "string",
  "expression": "string",
  "type": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "id": 0,
  "description": "string",
  "attribute": "string",
  "expression": "string",
  "type": "string"
}`;

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

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

### Python

```python
import requests

body = '''{
  "id": 0,
  "description": "string",
  "attribute": "string",
  "expression": "string",
  "type": "string"
}'''

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


## Fetch an Attribute

`GET /attributes/computed/{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: Attribute

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

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

- `description` (optional)
  Type: string
  
  Human readable name of the attribute

- `attribute` (optional)
  Type: string
  
  Attribute name used in expressions

- `expression` (optional)
  Type: string
  
  Expression that defines how the attribute is calculated

- `type` (optional)
  Type: string
  
  String|Number|Boolean

- 401: Unauthorized

- 404: Not found

## Examples

### cURL

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

### JavaScript

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

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

### Python

```python
import requests

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


## Update an Attribute

`PUT /attributes/computed/{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: Attribute

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

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

- `description` (optional)
  Type: string
  
  Human readable name of the attribute

- `attribute` (optional)
  Type: string
  
  Attribute name used in expressions

- `expression` (optional)
  Type: string
  
  Expression that defines how the attribute is calculated

- `type` (optional)
  Type: string
  
  String|Number|Boolean

Responses:

- 200: OK

Content type: application/json

Type: Attribute

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

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

- `description` (optional)
  Type: string
  
  Human readable name of the attribute

- `attribute` (optional)
  Type: string
  
  Attribute name used in expressions

- `expression` (optional)
  Type: string
  
  Expression that defines how the attribute is calculated

- `type` (optional)
  Type: string
  
  String|Number|Boolean

- 400: Bad request

- 401: Unauthorized

## Examples

### cURL

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

### JavaScript

```javascript
const body = `{
  "id": 0,
  "description": "string",
  "attribute": "string",
  "expression": "string",
  "type": "string"
}`;

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

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

### Python

```python
import requests

body = '''{
  "id": 0,
  "description": "string",
  "attribute": "string",
  "expression": "string",
  "type": "string"
}'''

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


## Delete an Attribute

`DELETE /attributes/computed/{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/attributes/computed/0' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE'
```

### JavaScript

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

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

### Python

```python
import requests

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