0

Cancel task

by
Published Nov 2, 2023

Cancels a task. **[Permissions](#permissions) required:** either of: * *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg). * Creator of the task.

Script jira
  • Submitted by hugo697 Typescript (fetch-only)
    Created 525 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Cancel task
    8
     * Cancels a task.
    9
    
    
    10
    **[Permissions](#permissions) required:** either of:
    11
    
    
    12
     *  *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
    13
     *  Creator of the task.
    14
     */
    15
    export async function main(auth: Jira, taskId: string) {
    16
      const url = new URL(
    17
        `https://${auth.domain}.atlassian.net/rest/api/2/task/${taskId}/cancel`
    18
      );
    19
    
    
    20
      const response = await fetch(url, {
    21
        method: "POST",
    22
        headers: {
    23
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    24
        },
    25
        body: undefined,
    26
      });
    27
      if (!response.ok) {
    28
        const text = await response.text();
    29
        throw new Error(`${response.status} ${text}`);
    30
      }
    31
      return await response.json();
    32
    }
    33