0

Get Task

by
Published Nov 2, 2023

Get the status and progress of a long-running asynchronous task (e.g. a bulk operation) by its task ID.

Script jira Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 8 days ago
1
//native
2

3
/**
4
 * Get Task
5
 * Get the status and progress of a long-running asynchronous task (e.g. a bulk operation) by its task ID.
6
 */
7
export async function main(auth: RT.Jira, task_id: string) {
8
  const url = new URL(
9
    `https://${auth.domain}.atlassian.net/rest/api/3/task/${task_id}`
10
  )
11

12
  const response = await fetch(url, {
13
    method: "GET",
14
    headers: {
15
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
16
      Accept: "application/json",
17
    },
18
  })
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 532 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Get task
    8
     * Returns the status of a [long-running asynchronous task](#async).
    9
     */
    10
    export async function main(auth: Jira, taskId: string) {
    11
      const url = new URL(
    12
        `https://${auth.domain}.atlassian.net/rest/api/2/task/${taskId}`
    13
      );
    14
    
    
    15
      const response = await fetch(url, {
    16
        method: "GET",
    17
        headers: {
    18
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    19
        },
    20
        body: undefined,
    21
      });
    22
      if (!response.ok) {
    23
        const text = await response.text();
    24
        throw new Error(`${response.status} ${text}`);
    25
      }
    26
      return await response.json();
    27
    }
    28