# Positions

Retrieving raw location information

## Fetch a list of Positions

`GET /positions`

We strongly recommend using [Traccar WebSocket API](https://www.traccar.org/traccar-api/) instead of periodically polling positions endpoint. Without any params, it returns a list of last known positions for all the user's Devices. _from_ and _to_ fields are not required with _id_.

Authentication (security requirement alternatives):

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

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

Parameters:

- `deviceId` (query, integer, optional) - _deviceId_ is optional, but requires the _from_ and _to_ parameters when used
  Type: integer

- `from` (query, string, date-time, optional) - in ISO 8601 format. eg. `1963-11-22T18:30:00Z`
  Type: string, date-time

- `to` (query, string, date-time, optional) - in ISO 8601 format. eg. `1963-11-22T18:30:00Z`
  Type: string, date-time

- `id` (query, integer, optional) - To fetch one or more positions. Multiple params can be passed like `id=31&id=42`
  Type: integer

Responses:

- 200: OK

Content type: application/json

Type: Array<Position>

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

Content type: text/csv

Type: Array<Position>

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

Content type: application/gpx+xml

Type: Array<Position>

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

- 401: Unauthorized

## Examples

### cURL

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

### JavaScript

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

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

### Python

```python
import requests

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


## Deletes all the Positions of a device in the time span specified

`DELETE /positions`

Authentication (security requirement alternatives):

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

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

Parameters:

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

- `from` (query, string, date-time, required) - in ISO 8601 format. eg. `1963-11-22T18:30:00Z`
  Type: string, date-time

- `to` (query, string, date-time, required) - in ISO 8601 format. eg. `1963-11-22T18:30:00Z`
  Type: string, date-time

Responses:

- 204: No Content

- 400: Bad request

## Examples

### cURL

```bash
curl -X DELETE 'https://demo.traccar.org/api/positions?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE'
```

### JavaScript

```javascript
const response = await fetch('https://demo.traccar.org/api/positions?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z', {
  method: 'DELETE',
  headers: {
    'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
  },
});

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

### Python

```python
import requests

response = requests.delete(
    'https://demo.traccar.org/api/positions?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z',
    headers={
        'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
    },
)
print(response.text)
```


## Delete a Position

`DELETE /positions/{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

- 404: Not found

## Examples

### cURL

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

### JavaScript

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

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

### Python

```python
import requests

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


## Export Positions as KML

`GET /positions/kml`

Authentication (security requirement alternatives):

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

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

Parameters:

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

- `from` (query, string, date-time, required)
  Type: string, date-time

- `to` (query, string, date-time, required)
  Type: string, date-time

Responses:

- 200: OK

Content type: application/vnd.google-earth.kml+xml

Type: string, binary

- 401: Unauthorized

## Examples

### cURL

```bash
curl -X GET 'https://demo.traccar.org/api/positions/kml?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE'
```

### JavaScript

```javascript
const response = await fetch('https://demo.traccar.org/api/positions/kml?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z', {
  method: 'GET',
  headers: {
    'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
  },
});

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

### Python

```python
import requests

response = requests.get(
    'https://demo.traccar.org/api/positions/kml?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z',
    headers={
        'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
    },
)
print(response.text)
```


## Export Positions as CSV

`GET /positions/csv`

Authentication (security requirement alternatives):

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

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

Parameters:

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

- `geofenceId` (query, integer, optional)
  Type: integer

- `from` (query, string, date-time, required)
  Type: string, date-time

- `to` (query, string, date-time, required)
  Type: string, date-time

Responses:

- 200: OK

Content type: text/csv

Type: string, binary

- 401: Unauthorized

## Examples

### cURL

```bash
curl -X GET 'https://demo.traccar.org/api/positions/csv?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE'
```

### JavaScript

```javascript
const response = await fetch('https://demo.traccar.org/api/positions/csv?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z', {
  method: 'GET',
  headers: {
    'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
  },
});

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

### Python

```python
import requests

response = requests.get(
    'https://demo.traccar.org/api/positions/csv?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z',
    headers={
        'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
    },
)
print(response.text)
```


## Export Positions as GPX

`GET /positions/gpx`

Authentication (security requirement alternatives):

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

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

Parameters:

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

- `from` (query, string, date-time, required)
  Type: string, date-time

- `to` (query, string, date-time, required)
  Type: string, date-time

Responses:

- 200: OK

Content type: application/gpx+xml

Type: string, binary

- 401: Unauthorized

## Examples

### cURL

```bash
curl -X GET 'https://demo.traccar.org/api/positions/gpx?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z' \
  -H 'Authorization: Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE'
```

### JavaScript

```javascript
const response = await fetch('https://demo.traccar.org/api/positions/gpx?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z', {
  method: 'GET',
  headers: {
    'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
  },
});

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

### Python

```python
import requests

response = requests.get(
    'https://demo.traccar.org/api/positions/gpx?deviceId=0&from=2024-01-15T09%3A30%3A00Z&to=2024-01-15T09%3A30%3A00Z',
    headers={
        'Authorization': 'Basic WU9VUl9VU0VSTkFNRTpZT1VSX1BBU1NXT1JE',
    },
)
print(response.text)
```
