0

Update Initiative

by
Published today

Update an initiative's name, description, status, owner or target date.

Script linear Verified

The script

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

3
/**
4
 * Update Initiative
5
 * Update an initiative. Only the fields you set are changed. Status: Planned, Active, Completed. target_date is YYYY-MM-DD.
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  initiative_id: string,
10
  name: string | undefined,
11
  description: string | undefined,
12
  content: string | undefined,
13
  status:
14
    "Planned" | "Active" | "Completed" | "Proposed" | "Canceled" | undefined,
15
  owner_id: string | undefined,
16
  target_date: string | undefined
17
) {
18
  const response = await fetch("https://api.linear.app/graphql", {
19
    method: "POST",
20
    headers: {
21
      Authorization: auth.apiKey,
22
      "Content-Type": "application/json",
23
      Accept: "application/json",
24
    },
25
    body: JSON.stringify({
26
      query: `mutation ($id: String!, $input: InitiativeUpdateInput!) { initiativeUpdate(id: $id, input: $input) { success initiative { id name description url status health targetDate createdAt updatedAt archivedAt owner { id name } projects { nodes { id name } } } } }`,
27
      variables: {
28
        id: initiative_id,
29
        input: {
30
          name: name || undefined,
31
          description: description || undefined,
32
          content: content || undefined,
33
          status: status || undefined,
34
          ownerId: owner_id || undefined,
35
          targetDate: target_date || undefined,
36
        },
37
      },
38
    }),
39
  })
40

41
  if (!response.ok) {
42
    throw new Error(`${response.status} ${await response.text()}`)
43
  }
44

45
  const { data, errors } = await response.json()
46
  if (errors) {
47
    throw new Error(JSON.stringify(errors))
48
  }
49

50
  return data.initiativeUpdate
51
}
52