0

Create batch tasks

Published today

Queue up to 100 search, fetch or research calls to run asynchronously in one request. Poll each returned task with Get task.

Script linkup Verified

The script

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

3
/**
4
 * Create batch tasks
5
 * Queue up to 100 search, fetch or research calls to run asynchronously in one request. Poll each returned task with Get task.
6
 */
7
export async function main(
8
  auth: RT.Linkup,
9
  tasks: {
10
    type: "search" | "fetch" | "research"
11
    input: { [key: string]: any }
12
  }[]
13
) {
14
  const url = new URL("https://api.linkup.so/v1/tasks")
15

16
  const response = await fetch(url, {
17
    method: "POST",
18
    headers: {
19
      Authorization: `Bearer ${auth.token}`,
20
      "Content-Type": "application/json",
21
      Accept: "application/json",
22
    },
23
    body: JSON.stringify(tasks),
24
  })
25

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

30
  return await response.json()
31
}
32