Edits history of script submission #24206 for ' Create batch tasks (linkup)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create batch tasks
     * Queue up to 100 search, fetch or research calls to run asynchronously in one request. Poll each returned task with Get task.
     */
    export async function main(
      auth: RT.Linkup,
      tasks: {
        type: "search" | "fetch" | "research"
        input: { [key: string]: any }
      }[]
    ) {
      const url = new URL("https://api.linkup.so/v1/tasks")
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify(tasks),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 3 hours ago