0

Create Initiative Update

by
Published today

Post a status update on an initiative.

Script linear Verified

The script

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

3
/**
4
 * Create Initiative Update
5
 * Post a status update on an initiative. body is Markdown. Health: onTrack, atRisk, offTrack.
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  initiative_id: string,
10
  body: string,
11
  health: "onTrack" | "atRisk" | "offTrack" | undefined
12
) {
13
  const response = await fetch("https://api.linear.app/graphql", {
14
    method: "POST",
15
    headers: {
16
      Authorization: auth.apiKey,
17
      "Content-Type": "application/json",
18
      Accept: "application/json",
19
    },
20
    body: JSON.stringify({
21
      query: `mutation ($input: InitiativeUpdateCreateInput!) { initiativeUpdateCreate(input: $input) { success initiativeUpdate { id body health url createdAt updatedAt user { id name } initiative { id name } } } }`,
22
      variables: {
23
        input: {
24
          initiativeId: initiative_id,
25
          body,
26
          health: health || undefined,
27
        },
28
      },
29
    }),
30
  })
31

32
  if (!response.ok) {
33
    throw new Error(`${response.status} ${await response.text()}`)
34
  }
35

36
  const { data, errors } = await response.json()
37
  if (errors) {
38
    throw new Error(JSON.stringify(errors))
39
  }
40

41
  return data.initiativeUpdateCreate
42
}
43