Create related work
One script reply has been approved by the moderators Verified

Creates a related work for the given version. You can only create a generic link type of related works via this API. relatedWorkId will be auto-generated UUID, that does not need to be provided.

This operation can be accessed anonymously.

Permissions required: Resolve issues: and Edit issues Managing project permissions for the project that contains the version.

Created by hugo697 879 days ago
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
 * Create related work
8
 * Creates a related work for the given version. You can only create a generic link type of related works via this API. relatedWorkId will be auto-generated UUID, that does not need to be provided.
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: "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