0

Get issue security levels

by
Published Nov 2, 2023

Returns a [paginated](#pagination) list of issue security levels. Only issue security levels in the context of classic projects are returned. Filtering using IDs is inclusive: if you specify both security scheme IDs and level IDs, the result will include both specified issue security levels and all issue security levels from the specified schemes. **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).

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
     * Get issue security levels
    8
     * Returns a [paginated](#pagination) list of issue security levels.
    9
    
    
    10
    Only issue security levels in the context of classic projects are returned.
    11
    
    
    12
    Filtering using IDs is inclusive: if you specify both security scheme IDs and level IDs, the result will include both specified issue security levels and all issue security levels from the specified schemes.
    13
    
    
    14
    **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
    15
     */
    16
    export async function main(
    17
      auth: Jira,
    18
      startAt: string | undefined,
    19
      maxResults: string | undefined,
    20
      id: string | undefined,
    21
      schemeId: string | undefined,
    22
      onlyDefault: string | undefined
    23
    ) {
    24
      const url = new URL(
    25
        `https://${auth.domain}.atlassian.net/rest/api/2/issuesecurityschemes/level`
    26
      );
    27
      for (const [k, v] of [
    28
        ["startAt", startAt],
    29
        ["maxResults", maxResults],
    30
        ["id", id],
    31
        ["schemeId", schemeId],
    32
        ["onlyDefault", onlyDefault],
    33
      ]) {
    34
        if (v !== undefined && v !== "") {
    35
          url.searchParams.append(k, v);
    36
        }
    37
      }
    38
      const response = await fetch(url, {
    39
        method: "GET",
    40
        headers: {
    41
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    42
        },
    43
        body: undefined,
    44
      });
    45
      if (!response.ok) {
    46
        const text = await response.text();
    47
        throw new Error(`${response.status} ${text}`);
    48
      }
    49
      return await response.json();
    50
    }
    51