0
Parse JQL query
One script reply has been approved by the moderators Verified

Parses and validates JQL queries.

Validation is performed in context of the current user.

This operation can be accessed anonymously.

Permissions required: None.

Created by hugo697 646 days ago Viewed 22534 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 646 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Parse JQL query
8
 * Parses and validates JQL queries.
9

10
Validation is performed in context of the current user.
11

12
This operation can be accessed anonymously.
13

14
**[Permissions](#permissions) required:** None.
15
 */
16
export async function main(
17
  auth: Jira,
18
  validation: "strict" | "warn" | "none" | undefined,
19
  body: { queries: string[] }
20
) {
21
  const url = new URL(
22
    `https://${auth.domain}.atlassian.net/rest/api/2/jql/parse`
23
  );
24
  for (const [k, v] of [["validation", validation]]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43