Update precomputations (apps)

Update the precomputation value of a function created by a Forge/Connect app. **[Permissions](#permissions) required:** An API for apps to update their own precomputations.

Script jira Verified

by hugo697 ยท 11/2/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Update precomputations (apps)
8
 * Update the precomputation value of a function created by a Forge/Connect app.
9

10
**[Permissions](#permissions) required:** An API for apps to update their own precomputations.
11
 */
12
export async function main(
13
  auth: Jira,
14
  body: { values?: { error?: string; id: string; value?: string }[] }
15
) {
16
  const url = new URL(
17
    `https://${auth.domain}.atlassian.net/rest/api/2/jql/function/computation`
18
  );
19

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