0

Get attachment metadata

Published Nov 2, 2023

Returns the metadata for an attachment. Note that the attachment itself is not returned. This operation can be accessed anonymously. **[Permissions](#permissions) required:** * *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in. * If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.

Script jira
  • Submitted by hugo697 Typescript (fetch-only)
    Created 565 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Get attachment metadata
    8
     * Returns the metadata for an attachment. Note that the attachment itself is not returned.
    9
    
    
    10
    This operation can be accessed anonymously.
    11
    
    
    12
    **[Permissions](#permissions) required:**
    13
    
    
    14
     *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.
    15
     *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
    16
     */
    17
    export async function main(auth: Jira, id: string) {
    18
      const url = new URL(
    19
        `https://${auth.domain}.atlassian.net/rest/api/2/attachment/${id}`
    20
      );
    21
    
    
    22
      const response = await fetch(url, {
    23
        method: "GET",
    24
        headers: {
    25
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    26
        },
    27
        body: undefined,
    28
      });
    29
      if (!response.ok) {
    30
        const text = await response.text();
    31
        throw new Error(`${response.status} ${text}`);
    32
      }
    33
      return await response.json();
    34
    }
    35