Set project avatar

Sets the avatar displayed for a project. Use [Load project avatar](#api-rest-api-2-project-projectIdOrKey-avatar2-post) to store avatars against the project, before using this operation to set the displayed avatar. **[Permissions](#permissions) required:** *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg).

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 avatar
8
 * Sets the avatar displayed for a project.
9

10
Use [Load project avatar](#api-rest-api-2-project-projectIdOrKey-avatar2-post) to store avatars against the project, before using this operation to set the displayed avatar.
11

12
**[Permissions](#permissions) required:** *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg).
13
 */
14
export async function main(
15
  auth: Jira,
16
  projectIdOrKey: string,
17
  body: {
18
    fileName?: string;
19
    id: string;
20
    isDeletable?: boolean;
21
    isSelected?: boolean;
22
    isSystemAvatar?: boolean;
23
    owner?: string;
24
    urls?: { [k: string]: string };
25
    [k: string]: unknown;
26
  }
27
) {
28
  const url = new URL(
29
    `https://${auth.domain}.atlassian.net/rest/api/2/project/${projectIdOrKey}/avatar`
30
  );
31

32
  const response = await fetch(url, {
33
    method: "PUT",
34
    headers: {
35
      "Content-Type": "application/json",
36
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
37
    },
38
    body: JSON.stringify(body),
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46