Edits history of script submission #23363 for ' Add Watcher to Issue (jira)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Add Watcher to Issue
     * Add a user to an issue's watcher list by account ID (find one with Get Users).
     */
    export async function main(
      auth: RT.Jira,
      issue_id_or_key: string,
      account_id: string
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/3/issue/${issue_id_or_key}/watchers`
      )
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify(account_id),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      if (response.status === 204) return { success: true }
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago