0

Create Project Update

by
Published today

Post a status update on a project.

Script linear Verified

The script

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

3
/**
4
 * Create Project Update
5
 * Post a status update on a project. body is Markdown. Health: onTrack, atRisk, offTrack.
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  project_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: ProjectUpdateCreateInput!) { projectUpdateCreate(input: $input) { success projectUpdate { id body health url createdAt updatedAt user { id name } project { id name } } } }`,
22
      variables: {
23
        input: { projectId: project_id, body, health: health || undefined },
24
      },
25
    }),
26
  })
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  const { data, errors } = await response.json()
33
  if (errors) {
34
    throw new Error(JSON.stringify(errors))
35
  }
36

37
  return data.projectUpdateCreate
38
}
39