Search for issues using JQL (POST)
One script reply has been approved by the moderators Verified

Searches for issues using [JQL](https://confluence.

Created by hugo697 879 days ago Picked 5 times
Submitted by hugo697 Typescript (fetch-only)
Verified 327 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Search for issues using JQL (POST)
8
 * Searches for issues using [JQL](https://confluence.
9
 */
10
export async function main(
11
  auth: Jira,
12
  body: {
13
    expand?: string[];
14
    fields?: string[];
15
    fieldsByKeys?: boolean;
16
    jql?: string;
17
    maxResults?: number;
18
    properties?: string[];
19
    startAt?: number;
20
    validateQuery?: "strict" | "warn" | "none" | "true" | "false";
21
  }
22
) {
23
  const url = new URL(`https://${auth.domain}.atlassian.net/rest/api/2/search`);
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39