# Recurring tasks

Some tasks happen on regular basis, and it's tedious to create them by hand every time. Task schedules is the way to automate this process. At the beginning of each day (moments after 00:00 AM according to [user's timezone setting](https://navixy.com/docs/navixy-api/user-api/backend-api/resources/commons/user/settings/index)), schedule checked and if there are tasks which start at this day, they are created and assigned to employees (if assignee specified).

Schedule entries are very similar to tasks, main difference is that `from` and `to` containing specific date and time replaced with `from_time`, `duration` and `parameters`.

## Task schedule entry object

```json
{
    "id": 111,
    "user_id": 3,
    "tracker_id": 22,
    "location": {
        "lat": 53.787154,
        "lng": 9.757980,
        "address": "Moltkestrasse 32",
        "radius": 150
    },
    "label": "Shop",
    "description": "Buy things",
    "from_time": "12:34:00",
    "duration": 60,
    "max_delay" : 5,
    "min_stay_duration": 0,
    "min_arrival_duration": 0,
    "parameters": {
        "type": "weekdays",
        "weekdays": [1, 5, 6]
    },
    "tags": [1, 2],
    "form_template_id": 1
}
```

* `id` - int. Primary key. Used in the update call, *IGNORED* in create.
* `user_id` - int. User ID. *IGNORED* in create/update.
* `tracker_id` - int. An ID of the tracker to which all generated tasks assigned. Nullable.
* `location` - location associated with this task. Cannot be null.
  * `address` - string. Address of the location.
  * `radius` - int. Radius of location zone in meters.
* `from_time` - string time. Time of day which defines start of the task within the days.
* `duration` - int. Total duration in minutes between "from" and "to" for generated tasks.
* `max_delay` - int. Maximum allowed task completion delay in minutes.
* `min_stay_duration` - int. Minimum duration of stay in task zone for task completion, minutes.
* `min_arrival_duration` - int. Visits less than these values will be ignored, minutes.
* `parameters` - schedule parameters can be "weekdays" or "month\_days". Described below.
* `tags` - int array. List of tag IDs.
* `form_template_id` - int. Form template ID. Nullable.

## API actions

API base path: `task/schedule`.

### create

Creates new task schedule entry.

**required sub-user rights**: `task_update`.

#### Parameters

| name     | description                                                 | type        |
| -------- | ----------------------------------------------------------- | ----------- |
| schedule | `schedule_entry` object without fields which are *IGNORED*. | JSON object |

#### Examples

cURL

{% code overflow="wrap" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/task/schedule/create' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b", "schedule": {"tracker_id": 22, "location": {"lat": 53.787154, "lng": 9.757980, "address": "Moltkestrasse 32", "radius": 150}, "label": "Shop", "description": "Buy things", "from_time": "12:34:00", "duration": 60, "max_delay" : 5, "min_stay_duration": 0, "min_arrival_duration": 0, "parameters": {"type": "weekdays", "weekdays": [1, 5, 6]}, "tags": [1, 2], "form_template_id": 1}'
```

{% endcode %}

#### Response

```json
{
    "success": true,
    "id": 111
}
```

* `id` - int. An ID of the created schedule entry.

#### Errors

* 201 – Not found in the database - if schedule.tracker\_id belongs to nonexistent tracker.
* 204 – Entity not found - if schedule.form\_template\_id belongs to nonexistent form template.
* 208 – Device blocked - if tracker exists but was blocked due to tariff restrictions or some other reason.
* 236 – Feature unavailable due to tariff restrictions - if device's tariff does not allow usage of tasks.

### delete

Delete task schedule with the specified ID.

**required sub-user rights**: `task_update`.

#### Parameters

| name         | description                        | type |
| ------------ | ---------------------------------- | ---- |
| schedule\_id | ID of the task schedule to delete. | int  |

#### Examples

{% tabs %}
{% tab title="cURL" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/task/schedule/delete' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b", "schedule_id": 23144}'
```

{% endtab %}

{% tab title="HTTP GET" %}
{% code overflow="wrap" %}

```http
https://api.eu.navixy.com/v2/task/schedule/delete?hash=a6aa75587e5c59c32d347da438505fc3&schedule_id=23144
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Response

```json
{ "success": true }
```

#### Errors

* 201 – Not found in the database - if there is no task schedule with such an ID.

### list

Get all task or route schedules belonging to user with optional filtering.\
Also this call returns all unassigned task schedules.

#### Parameters

| name     | description                                                                                                   | type         |
| -------- | ------------------------------------------------------------------------------------------------------------- | ------------ |
| trackers | Optional. IDs of the trackers to which task schedule is assigned.                                             | int array    |
| filter   | Optional. Filter for task schedule label and description.                                                     | string       |
| tag\_ids | Optional. Tag IDs assigned to the task schedule. The schedules found must include all the tags from the list. | int array    |
| types    | Optional. Tasks of specific type will be returned in the list. Can be `task` or `route`. Default is `task`.   | string array |

#### Examples

{% tabs %}
{% tab title="cURL" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/task/schedule/list' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b"}'
```

{% endtab %}

{% tab title="HTTP GET" %}
{% code overflow="wrap" %}

```http
https://api.eu.navixy.com/v2/task/schedule/list?hash=a6aa75587e5c59c32d347da438505fc3
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Response

```json
{
    "success": true,
    "list": [{
         "id": 111,
         "user_id": 3,
         "tracker_id": 22,
         "location": {
             "lat": 53.787154,
             "lng": 9.757980,
             "address": "Moltkestrasse 32",
             "radius": 150
         },
         "label": "Shop",
         "description": "Buy things",
         "from_time": "12:34:00",
         "duration": 60,
         "max_delay" : 5,
         "min_stay_duration": 0,
         "min_arrival_duration": 0,
         "parameters": {
             "type": "weekdays",
             "weekdays": [1, 5, 6]
         },
         "tags": [1, 2],
         "form_template_id": 1
    }]
}
```

#### Errors

[General](https://navixy.com/docs/navixy-api/user-api/errors#error-codes) types only.

### read

Gets task, route or checkpoint schedule by specified ID.

#### Parameters

| name | description                                  | type |
| ---- | -------------------------------------------- | ---- |
| id   | An ID of task, route or checkpoint schedule. | int  |

#### Examples

{% tabs %}
{% tab title="cURL" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/task/schedule/read' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b", "id": 12314}'
```

{% endtab %}

{% tab title="HTTP GET" %}
{% code overflow="wrap" %}

```http
https://api.eu.navixy.com/v2/task/schedule/read?hash=a6aa75587e5c59c32d347da438505fc3&id=12314
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Response

```json
{
    "success": true,
    "value": {
         "id": 111,
         "user_id": 3,
         "tracker_id": 22,
         "label": "Shop",
         "description": "Buy things",
         "parameters": {
            "type": "weekdays",
            "weekdays": [1, 5, 6]
         }
    },
    "checkpoints": [{
        "id": 111,
        "user_id": 3,
        "tracker_id": 22,
        "label": "Shop",
        "description": "Buy things",
        "parent_id": 1,
        "order": 0,
        "location": {
            "lat": 53.787154,
            "lng": 9.757980,
            "address": "Moltkestrasse 32",
            "radius": 150
        },
        "max_delay" : 5,
        "min_stay_duration": 0,
        "min_arrival_duration": 0,
        "from_time": "12:34:00",
        "duration": 60,
        "tags": [1, 2],
        "form_template_id": 1
    }]
}
```

* `value` - \<schedule\_entry> object.
* `checkpoints` - if value is \<route\_schedule\_entry>.

#### Errors

[General](https://navixy.com/docs/navixy-api/user-api/errors#error-codes) types only.

### update

Updates existing task schedule.

**required sub-user rights**: `task_update`.

#### Parameters

| name     | description                                                 | type        |
| -------- | ----------------------------------------------------------- | ----------- |
| schedule | `schedule_entry` object without fields which are *IGNORED*. | JSON object |

#### Examples

cURL

{% code overflow="wrap" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/task/schedule/update' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b", "schedule": {"tracker_id": 22, "location": {"lat": 53.787154, "lng": 9.757980, "address": "Moltkestrasse 32", "radius": 150}, "label": "Shop", "description": "Buy things", "from_time": "12:34:00", "duration": 60, "max_delay" : 5, "min_stay_duration": 0, "min_arrival_duration": 0, "parameters": {"type": "weekdays", "weekdays": [1, 5, 6]}, "tags": [1, 2], "form_template_id": 1}'
```

{% endcode %}

#### Response

```json
{
    "success": true
}
```

#### Errors

* 201 – Not found in the database - if schedule.tracker\_id belongs to nonexistent tracker.
* 204 – Entity not found - if there is no task schedule with specified ID.
* 208 – Device blocked - if tracker exists but was blocked due to tariff restrictions or some other reason.
* 236 – Feature unavailable due to tariff restrictions - if device's tariff does not allow usage of tasks.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://navixy.com/docs/navixy-api/user-api/backend-api/resources/field-service/task/schedule/index.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
