Get a single initiative by ID.
1
//native
2
3
/**
4
* Get Initiative
5
* Get a single initiative by its ID, with its projects and latest update.
6
*/
7
export async function main(auth: RT.Linear, initiative_id: string) {
8
const response = await fetch("https://api.linear.app/graphql", {
9
method: "POST",
10
headers: {
11
Authorization: auth.apiKey,
12
"Content-Type": "application/json",
13
Accept: "application/json",
14
},
15
body: JSON.stringify({
16
query: `query ($id: String!) { initiative(id: $id) { id name description url status health targetDate createdAt updatedAt archivedAt owner { id name } projects { nodes { id name } } content lastUpdate { id body health createdAt } } }`,
17
variables: { id: initiative_id },
18
}),
19
})
20
21
if (!response.ok) {
22
throw new Error(`${response.status} ${await response.text()}`)
23
}
24
25
const { data, errors } = await response.json()
26
if (errors) {
27
throw new Error(JSON.stringify(errors))
28
29
30
return data.initiative
31
32