Set project property

Sets the value of the [project property](https://developer.

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
 * Set project property
8
 * Sets the value of the [project property](https://developer.
9
 */
10
export async function main(
11
  auth: Jira,
12
  projectIdOrKey: string,
13
  propertyKey: string,
14
  body: { [k: string]: unknown }
15
) {
16
  const url = new URL(
17
    `https://${auth.domain}.atlassian.net/rest/api/2/project/${projectIdOrKey}/properties/${propertyKey}`
18
  );
19

20
  const response = await fetch(url, {
21
    method: "PUT",
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