0

Get screens

Published Nov 2, 2023

Returns a [paginated](#pagination) list of all screens or those specified by one or more screen IDs. **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).

Script jira
  • Submitted by hugo697 Typescript (fetch-only)
    Created 567 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Get screens
    8
     * Returns a [paginated](#pagination) list of all screens or those specified by one or more screen IDs.
    9
    
    
    10
    **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
    11
     */
    12
    export async function main(
    13
      auth: Jira,
    14
      startAt: string | undefined,
    15
      maxResults: string | undefined,
    16
      id: string | undefined,
    17
      queryString: string | undefined,
    18
      scope: string | undefined,
    19
      orderBy: "name" | "-name" | "+name" | "id" | "-id" | "+id" | undefined
    20
    ) {
    21
      const url = new URL(
    22
        `https://${auth.domain}.atlassian.net/rest/api/2/screens`
    23
      );
    24
      for (const [k, v] of [
    25
        ["startAt", startAt],
    26
        ["maxResults", maxResults],
    27
        ["id", id],
    28
        ["queryString", queryString],
    29
        ["scope", scope],
    30
        ["orderBy", orderBy],
    31
      ]) {
    32
        if (v !== undefined && v !== "") {
    33
          url.searchParams.append(k, v);
    34
        }
    35
      }
    36
      const response = await fetch(url, {
    37
        method: "GET",
    38
        headers: {
    39
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    40
        },
    41
        body: undefined,
    42
      });
    43
      if (!response.ok) {
    44
        const text = await response.text();
    45
        throw new Error(`${response.status} ${text}`);
    46
      }
    47
      return await response.json();
    48
    }
    49