0

Update related work

by
Published Nov 2, 2023

Updates the given related work. You can only update generic link related works via Rest APIs. Any archived version related works can't be edited. This operation can be accessed anonymously. **[Permissions](#permissions) required:** *Resolve issues:* and *Edit issues* [Managing project permissions](https://confluence.atlassian.com/adminjiraserver/managing-project-permissions-938847145.html) for the project that contains the version.

Script jira Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 416 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Update related work
8
 * Updates the given related work. You can only update generic link related works via Rest APIs. Any archived version related works can't be edited.
9

10
This operation can be accessed anonymously.
11

12
**[Permissions](#permissions) required:** *Resolve issues:* and *Edit issues* [Managing project permissions](https://confluence.atlassian.com/adminjiraserver/managing-project-permissions-938847145.html) for the project that contains the version.
13
 */
14
export async function main(
15
  auth: Jira,
16
  id: string,
17
  body: {
18
    category: string;
19
    issueId?: number;
20
    relatedWorkId?: string;
21
    title?: string;
22
    url?: string;
23
  }
24
) {
25
  const url = new URL(
26
    `https://${auth.domain}.atlassian.net/rest/api/2/version/${id}/relatedwork`
27
  );
28

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