Tasks methods

The Tasks SDK methods enable you to perform CRUD operations with Gtmhub Tasks in your UI App. For example, your UI App may enable users to create Tasks with it, or automatically update the user's tasks based on their interaction with the app. Check out the Your First UI App Tutorial for an exampl of a UI App that enable susers to create Gtmhub tasks via the Tasks SDK methods.

NOTE: Before you start using the SDK methods, ensure you have imported and configured the SDK first.

createTask

This SKD method enables you to create a Task in the current Gtmhub account. To use the createTask method you must construct a payload representing the task object you are creating. Inside your payload you must specify the values of all task properties you need to set. Refer to the Create Task API Endpoint for more information about the available and required properties for a Gtmhub Task object.

Follow the example below to create a Task specifying its name, status and parentId.

const createTaskPayload = {
  name: "my-first-task",
  parentId:"", // goal.id or metric.id
  status:"todo",
};

sdk
  .createTask(createTaskPayload)
  .then((task) => console.log(task));

NOTE You must specify the Id of an Objective or Key Result as the Task parent. For example, you can use the getCurrentItem helper method dto get the Id of the Objective or key Result your UI App is currently opened for. Alternatively, you can use the getMetrics or getGoal methods to get a collection of Key Result or Objectives respectively and find the desired OKR Id.

getTask

To get a single Task use the getTask method and pass the desired task Id:

const taskId = "some-task-id";

sdk
  .getTask(taskId)
  .then((task) => console.log(task));

updateTask

To update a task from your UI app use the updateTask method. You must pass a payload object representing the properties you are updating. For example, to update the task name do the following:

const updateTaskpayload = {id: "some-task-id", name: "my-new-task-name"};

sdk
  .updateTask(updateTaskPayload)
  .then((task) => console.log(task));

NOTE: The payload must always contain the task Id.

deleteTask

To detele a task, use the deleteTask method and pass the task Id. For example:

const taskId = "some-task-id";

sdk.deleteTask(taskId);