Task commands

Task commands

Task Commands are used for updating task states, positions, and assignments. Commands are processed asynchronously and support batching for efficient bulk operations.

Please find the tehnical API specification here for task commands.

Available actions

ActionDescription
updateUpdate task data (including position)
assignAssign task to a worker
reassignReassign to a different worker
unassignRemove assignee
acceptWorker accepts the task
unacceptWorker reverts acceptance
rejectWorker rejects assignment
transitWorker traveling to location
activateWorker begins work
completeMark as completed
failMark as failed
cancelCancel the task
restartRestart a failed task

Creating a task command

HTTP request

POST https://api.gsmtasks.com/task_commands/

Request fields

FieldTypeRequiredDescription
taskURLYesThe task URL this command applies to
external_idStringYesUnique identifier generated by the client
timeDateTimeYesWhen the interaction occurred
actionStringYesThe action to perform (see Available Actions)
assigneeURLFor assign/reassignThe user to assign the task to
task_dataObjectFor updateData to update on the task
notesStringNoOptional notes for the command
locationPointNoGeographic location where command was issued

Single command example

{
  "task": "https://api.gsmtasks.com/tasks/e9ba6977-ddc4-41b9-b90b-1ae9b37b3c05/",
  "external_id": "e31017a8889b8f106bd59f5f6febe40eb1f8c51a",
  "time": "2022-09-09T13:43:00.580000+03:00",
  "action": "transit"
}

Response (accepted)

{
  "id": "856ae165-9595-4f1d-8377-6f4c4db073d1",
  "url": "https://api.gsmtasks.com/task_commands/856ae165-9595-4f1d-8377-6f4c4db073d1/",
  "account": "https://api.gsmtasks.com/accounts/a6f60fdf-d87b-4c5d-b5ec-67a90cd16236/",
  "task": "https://api.gsmtasks.com/tasks/e9ba6977-ddc4-41b9-b90b-1ae9b37b3c05/",
  "external_id": "e31017a8889b8f106bd59f5f6febe40eb1f8c51a",
  "time": "2022-09-09T13:43:00.580000+03:00",
  "action": "transit",
  "user": "https://api.gsmtasks.com/users/8495e730-e5c2-400c-8ffc-ad830d4fa6a2/",
  "notes": "",
  "location": null,
  "assignee": null,
  "state": "accepted",
  "error_message": "",
  "task_data": {},
  "accepted_at": "2022-09-09T13:43:01.052384+03:00",
  "rejected_at": null,
  "created_at": "2022-09-09T13:43:00.993254+03:00",
  "updated_at": "2022-09-09T13:43:01.052490+03:00"
}

Response (rejected)

When a command cannot be applied (e.g., invalid state transition or permission denied):

{
  "id": "71dd847f-596d-48f1-bf50-db6c8cee4796",
  "url": "https://api.gsmtasks.com/task_commands/71dd847f-596d-48f1-bf50-db6c8cee4796/",
  "account": "https://api.gsmtasks.com/accounts/a6f60fdf-d87b-4c5d-b5ec-67a90cd16236/",
  "task": "https://api.gsmtasks.com/tasks/e9ba6977-ddc4-41b9-b90b-1ae9b37b3c05/",
  "external_id": "86ea541b917fa464023cfeef05dc6d79df02bf10",
  "time": "2022-09-09T13:46:32.556000+03:00",
  "action": "accept",
  "user": "https://api.gsmtasks.com/users/8495e730-e5c2-400c-8ffc-ad830d4fa6a2/",
  "notes": "",
  "location": null,
  "assignee": null,
  "state": "rejected",
  "error_message": "Can't switch from state 'accepted' using method 'accept'",
  "task_data": {},
  "accepted_at": null,
  "rejected_at": "2022-09-09T13:46:32.735993+03:00",
  "created_at": "2022-09-09T13:46:32.705774+03:00",
  "updated_at": "2022-09-09T13:46:32.736151+03:00"
}

Batch commands

HTTP request

POST https://api.gsmtasks.com/task_commands/

Request

[
  {
    "task": "https://api.gsmtasks.com/tasks/e9ba6977-ddc4-41b9-b90b-1ae9b37b3c05/",
    "external_id": "e31017a8889b8f106bd59f5f6febe40eb1f8c51a",
    "time": "2022-09-09T13:43:00.580000+03:00",
    "action": "transit"
  },
  {
    "task": "https://api.gsmtasks.com/tasks/e9ba6977-ddc4-41b9-b90b-1ae9b37b3c05/",
    "external_id": "461505e9-38b5-4109-a15f-85375d41c4b8",
    "time": "2022-09-09T13:48:00.580000+03:00",
    "action": "activate"
  },
  {
    "task": "https://api.gsmtasks.com/tasks/e9ba6977-ddc4-41b9-b90b-1ae9b37b3c05/",
    "external_id": "63ea82de-e579-436d-a9b0-dceb42cc1ec0",
    "time": "2022-09-09T13:51:00.580000+03:00",
    "action": "complete"
  }
]

Updating task data

Use the update action with task_data to modify task fields.

Task data fields

FieldTypeDescription
positionFloatTask order in worker’s list
scheduled_timeDateTimeScheduled time for the task
durationDurationExpected task duration
metafieldsObjectCustom metadata
addressObjectTask address
contact_addressObjectContact address
routeURLRoute assignment

Update position (reordering)

Change the order of tasks in a worker’s list.

{
  "task": "https://api.gsmtasks.com/tasks/e1f228fe-cf4f-44ef-ad9f-6b5d4034a25c/",
  "external_id": "c3d4e5f6789012345678901234567890abcdef",
  "time": "2022-09-19T06:19:25.482Z",
  "action": "update",
  "task_data": {
    "position": 16343544103.775824
  }
}

Calculating position values

// Insert between two tasks
const newPosition = (taskAbove.position + taskBelow.position) / 2;
 
// Insert at the beginning
const newPosition = firstTask.position - 100;
 
// Insert at the end
const newPosition = lastTask.position + 100;
💡

Worker reordering is controlled by the account setting feature_allow_worker_reordering.

Update scheduled time

Set when the task should be executed.

{
  "task": "https://api.gsmtasks.com/tasks/e1f228fe-cf4f-44ef-ad9f-6b5d4034a25c/",
  "external_id": "a1b2c3d4e5f6789012345678901234567890abcd",
  "time": "2022-09-19T06:19:25.482Z",
  "action": "update",
  "task_data": {
    "scheduled_time": "2022-09-20T09:00:00Z"
  }
}

Update metafields

Add or modify custom metadata on a task.

{
  "task": "https://api.gsmtasks.com/tasks/e1f228fe-cf4f-44ef-ad9f-6b5d4034a25c/",
  "external_id": "b2c3d4e5f6789012345678901234567890abcde",
  "time": "2022-09-19T06:19:25.482Z",
  "action": "update",
  "task_data": {
    "metafields": {
      "priority": "high",
      "package_size": "large"
    }
  }
}

Update address

Change the task’s destination address.

{
  "task": "https://api.gsmtasks.com/tasks/e1f228fe-cf4f-44ef-ad9f-6b5d4034a25c/",
  "external_id": "d4e5f6789012345678901234567890abcdef01",
  "time": "2022-09-19T06:19:25.482Z",
  "action": "update",
  "task_data": {
    "address": {
      "raw_address": "123 New Street, London, UK",
      "location": {
        "type": "Point",
        "coordinates": [-0.1276, 51.5074]
      }
    }
  }
}

Update route

Assign the task to a specific route.

{
  "task": "https://api.gsmtasks.com/tasks/e1f228fe-cf4f-44ef-ad9f-6b5d4034a25c/",
  "external_id": "e5f6789012345678901234567890abcdef0123",
  "time": "2022-09-19T06:19:25.482Z",
  "action": "update",
  "task_data": {
    "route": "https://api.gsmtasks.com/routes/a1b2c3d4-e5f6-7890-abcd-ef0123456789/"
  }
}

Update duration

Set the expected time to complete the task.

{
  "task": "https://api.gsmtasks.com/tasks/e1f228fe-cf4f-44ef-ad9f-6b5d4034a25c/",
  "external_id": "f6789012345678901234567890abcdef012345",
  "time": "2022-09-19T06:19:25.482Z",
  "action": "update",
  "task_data": {
    "duration": "00:30:00"
  }
}

Assignment commands

Assign task

Assign an unassigned task to a worker.

{
  "task": "https://api.gsmtasks.com/tasks/abc123/",
  "external_id": "cmd-assign-001",
  "time": "2022-09-09T09:00:00Z",
  "action": "assign",
  "assignee": "https://api.gsmtasks.com/users/worker123/"
}

Reassign with position

Move a task to a different worker and set its position in their list.

{
  "task": "https://api.gsmtasks.com/tasks/e1f228fe-cf4f-44ef-ad9f-6b5d4034a25c/",
  "external_id": "f93b4be79be47e9913ed89c8d6e9bca9e2c21409",
  "time": "2022-09-19T06:19:25.482Z",
  "action": "reassign",
  "assignee": "https://api.gsmtasks.com/users/8495e730-e5c2-400c-8ffc-ad830d4fa6a2/",
  "task_data": {
    "position": 16343544103.775824
  }
}

Unassign task

Remove a task from its current worker.

{
  "task": "https://api.gsmtasks.com/tasks/abc123/",
  "external_id": "cmd-unassign-001",
  "time": "2022-09-09T09:00:00Z",
  "action": "unassign"
}