update_task
The unit/update_task request allows you to edit tasks. To create a new task, use unit/create_task. For information about how tasks work in the monitoring system, see Tasks.
Endpoint
svc=unit/update_task¶ms={
"itemId": <long>,
"taskId": <text>,
"props": {
"key1": <long>,
"key2": <text>,
.....
}
}
Request example:
https://hst-api.wialon.com/wialon/ajax.html?
svc=unit/update_task&
params={
"itemId": 1514,
"taskId": "6f6aeeebad9ebe64bda86924f8d379d8e6b06bd690c53da4aab526c5e221bdb266b52a50",
"props": {
"task_status": 2,
"task_priority": 3
}
}&
sid=SESSION_IDENTIFIER
Parameters
The request must contain the following parameters:
| Parameter | Description |
|---|---|
itemId |
The ID of the unit. |
taskId |
The ID of the task: a string hash of exactly 72 characters. It’s returned in the task_id field by messages/get_task_messages. |
props |
The object of properties to be updated (key-value pairs). Include only those properties that you want to update, because each update fully replaces the corresponding existing property. The only exception is task_params, which is merged with the parameters that the task already has. See the list of available properties below. |
Task properties
| Property | Description |
|---|---|
task_status |
The status of the task. Acceptable values are:
If you change the task status from Done or Rejected to any other status, or from any other status to Done, Rejected, or Paused, a comment is required. For details about task statuses in the monitoring system, see Changing the task status. |
task_priority |
The priority of the task. Acceptable values are:
|
task_assignee |
The ID of the user to whom the task is assigned. |
task_comments |
The array of task comments. The comment field must not be empty and must not exceed 500 characters. |
task_params |
A JSON object containing additional task parameters. Supported keys:
The keys that you don’t pass keep their previous values. This means that you can change a value that is already set, but you can’t delete it. |
Access rights
To work with the tasks of a unit, the following access rights to it are required:
| Access right | What it’s needed for |
|---|---|
| View object and its basic properties | Accessing the unit to view its tasks. |
| Request reports and messages | Viewing the tasks created for the unit, as tasks are stored as messages in the system. Without this right, the tasks of the unit aren’t returned by messages/get_task_messages, so you can’t get a taskId. |
| Edit task status and manage comments | Changing the task status as well as adding, editing, and deleting comments. unit/update_task requires this right for any update. |
| Edit tasks | Changing task_priority, and, in combination with the Act on behalf of this user access right to users, changing task_assignee. Also, includes the permissions granted by the Edit task status and manage comments access right. |
Managing comments
The task_comments array must contain all the comments that the task has after the update. Pass the existing comments with their id, and a new comment without it:
[
{ "id": 1, "comment": "Unit delivered to the service station." },
{ "id": 2, "comment": "Oil and filters replaced." },
{ "comment": "Spare parts ordered, waiting for delivery." }
]
If a comment has been previously added to the task, but its id isn’t included in the array, the comment is deleted.
For a new comment, the system assigns the next id (the comments of a task are numbered starting from 1) and sets the author to the current user. You can also pass the timestamp field with the time of the comment as a UNIX timestamp. By default, the system uses the current server time.
For an existing comment, only the text can be changed. If you change it, the system records who edited the comment and when.
For the same actions in the monitoring system, see Comments.
Adding a comment
To add a comment, pass an object of the following format in the task_comments array:
{ "comment": "Spare parts ordered, waiting for delivery." }
Editing a comment
To edit a comment, specify its ID in the task_comments array and include the new comment text:
{ "id": 2, "comment": "Oil and filters replaced. Next service due at 140000 km." }
Deleting a comment
To delete a comment, remove it from the task_comments array.
Adding or editing additional parameters
To add or edit additional task parameters, include the task_params object in the props parameter with the desired key-value pairs:
{
"itemId": 1514,
"taskId": "6f6aeeebad9ebe64bda86924f8d379d8e6b06bd690c53da4aab526c5e221bdb266b52a50",
"props": {
"task_params": {
"filled": 50.5,
"mileage": 125.8,
"cost": 150
}
}
}
Specify the filled and mileage values in the unit’s current measurement system (SI, US, imperial, or metric with gallons). The measurement system is set in the mu property of the unit. For details, see General properties. The charged, cost, and engine_hours values are stored as they are passed.
Updating several tasks at once
The unit/update_task request updates one task. To update several tasks at once (for example, to assign them to the same user, or to change their status or priority), combine unit/update_task requests in a core/batch request.
Each element of the params array is a separate unit/update_task request with its own itemId and taskId.
svc=core/batch¶ms={
"params": [
{
"svc": "unit/update_task",
"params": {
"itemId": 1514,
"taskId": "6f6aeeebad9ebe64bda86924f8d379d8e6b06bd690c53da4aab526c5e221bdb266b52a50",
"props": {
"task_status": 6,
"task_comments": [
{ "comment": "Checked by the operator." }
]
}
}
},
{
"svc": "unit/update_task",
"params": {
"itemId": 1515,
"taskId": "8a21bcb0ad9ebe64bda86924f8d379d8e6b06bd690c53da4aab526c5e221ff416a8d46d0",
"props": {
"task_status": 6,
"task_comments": [
{ "comment": "Checked by the operator." }
]
}
}
}
],
"flags": 0
}
Keep in mind the following:
| Rule | Description |
|---|---|
| Comments | If you change the status to Done (6), Rejected (5), or Paused (4), or from Done or Rejected to any other status, pass a comment in task_comments for each task. Otherwise, the corresponding request returns error 4 with the COMMENT_IS_REQUIRED reason, and the task keeps its previous properties. |
| Existing comments | task_comments replaces the whole array of comments of a task. If a task already has comments and you pass only a new one, the previous comments are deleted. To keep them, pass them together with their IDs, as described in Managing comments. |
| Access rights | The access rights are checked for each task separately. With "flags": 0, only the request to the unit that you have no rights to fails, and the other requests are executed. With "flags": 1, all the requests that follow the failed one return error 10. |
| Response | The response is an array with the result of each request in the same order in which the requests were sent. |
| Limitations | A core/batch request is limited by the size of the response and by the execution time. If the response is too large, the request returns error 6. If the execution time is exceeded, the remaining requests return error 10. |
For the description of the flags parameter, see core/batch.
Response
If the request is completed successfully, an empty response is returned.
{}
Otherwise, an error code is returned. Example:
{
"error": 5,
"reason": "TASK_NOT_FOUND"
}
Error codes
| Error code | Description | reason field value |
|---|---|---|
| 4 | Invalid input. A required parameter is missing or has a wrong type, taskId isn’t a 72-character string, or the properties in props can’t be applied (for example, the specified assignee doesn’t exist).The same code is returned if the status change requires a comment, but no new comment is passed in task_comments. |
INVALID_INPUT_PARAMSCOMMENT_IS_REQUIRED |
| 5 | The unit has no task with the specified taskId. |
TASK_NOT_FOUND |
| 6 | The specified comment ID isn’t found among the comments of the task, or the array contains the same ID twice. The UNKNOWN_ERROR reason means that tasks aren’t supported for the unit. |
INVALID_COMMENT_IDUNKNOWN_ERROR |
| 7 | Access denied. One of the following:
|
NO_ACCESS_TO_UNITNO_ACCESS_TO_USER |
For the general error codes, see Error codes.