0

Archive Issue

by
Published today

Archive an issue (or move it to the trash).

Script linear Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 1 hour ago
1
//native
2

3
/**
4
 * Archive Issue
5
 * Archive an issue. Set trash to move it to the trash instead (deleted after 30 days).
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  issue_id: string,
10
  trash: boolean = false
11
) {
12
  const response = await fetch("https://api.linear.app/graphql", {
13
    method: "POST",
14
    headers: {
15
      Authorization: auth.apiKey,
16
      "Content-Type": "application/json",
17
      Accept: "application/json",
18
    },
19
    body: JSON.stringify({
20
      query: `mutation ($id: String!, $trash: Boolean) { issueArchive(id: $id, trash: $trash) { success entity { id identifier archivedAt trashed } } }`,
21
      variables: { id: issue_id, trash },
22
    }),
23
  })
24

25
  if (!response.ok) {
26
    throw new Error(`${response.status} ${await response.text()}`)
27
  }
28

29
  const { data, errors } = await response.json()
30
  if (errors) {
31
    throw new Error(JSON.stringify(errors))
32
  }
33

34
  return data.issueArchive
35
}
36