Back to all

Fetching entity_tags associated to a task

Is there a more efficient way of fetching tags associated to a task?

From the API

https://developers.fieldwire.com/reference/get_tasks_tags

this does not take a task ID so it is not specific to a task. It also returns a complex object of array of array of UIDs, where one is a task ID and the other the tag ID.

To use this from working back from a task you need to:

  1. Get all the task_tags
  2. Get the task of interest
  3. Loop through the task tags array and then check the array at the current index contains the taskID, if so use the entity_tag ID,
  4. As there can be multiple tags per task, the full array needs to be searched and cannot be terminated early.

The response to Get all the task_tags can be reshaped for more efficient output (create a map of array - the key the task ID and the array is associated entity_tags) but adds complexity to client code.