Edits history of script submission #3772 for ' Delete attachment (jira)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Delete attachment
     * Deletes an attachment from an issue.
    
    This operation can be accessed anonymously.
    
    **[Permissions](#permissions) required:** For the project holding the issue containing the attachment:
    
     *  *Delete own attachments* [project permission](https://confluence.atlassian.com/x/yodKLg) to delete an attachment created by the calling user.
     *  *Delete all attachments* [project permission](https://confluence.atlassian.com/x/yodKLg) to delete an attachment created by any user.
     */
    export async function main(auth: Jira, id: string) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/attachment/${id}`
      );
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 396 days ago

  • nativets
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Delete attachment
     * Deletes an attachment from an issue.
    
    This operation can be accessed anonymously.
    
    **[Permissions](#permissions) required:** For the project holding the issue containing the attachment:
    
     *  *Delete own attachments* [project permission](https://confluence.atlassian.com/x/yodKLg) to delete an attachment created by the calling user.
     *  *Delete all attachments* [project permission](https://confluence.atlassian.com/x/yodKLg) to delete an attachment created by any user.
     */
    export async function main(auth: Jira, id: string) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/attachment/${id}`
      );
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 948 days ago