0

Fetch page

Published today

Fetch a single web page (HTML or PDF) as clean markdown, optionally extracting typed JSON with a schema.

Script linkup Verified

The script

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

3
/**
4
 * Fetch page
5
 * Fetch a single web page (HTML or PDF) as clean markdown, optionally extracting typed JSON with a schema.
6
 */
7
export async function main(
8
  auth: RT.Linkup,
9
  page_url: string,
10
  mode: "standard" | "pro" | undefined,
11
  render_js: boolean | undefined,
12
  extract_images: boolean | undefined,
13
  include_raw_content: boolean | undefined,
14
  schema: { [key: string]: any } | undefined,
15
  instructions: string | undefined
16
) {
17
  const url = new URL("https://api.linkup.so/v1/fetch")
18

19
  const hasSchema = schema != null && Object.keys(schema).length > 0
20

21
  const response = await fetch(url, {
22
    method: "POST",
23
    headers: {
24
      Authorization: `Bearer ${auth.token}`,
25
      "Content-Type": "application/json",
26
      Accept: "application/json",
27
    },
28
    body: JSON.stringify({
29
      url: page_url,
30
      mode: mode || undefined,
31
      renderJs: render_js || undefined,
32
      extractImages: extract_images || undefined,
33
      includeRawContent: include_raw_content || undefined,
34
      schema: hasSchema ? schema : undefined,
35
      instructions: hasSchema ? instructions || undefined : undefined,
36
    }),
37
  })
38

39
  if (!response.ok) {
40
    throw new Error(`${response.status} ${await response.text()}`)
41
  }
42

43
  return await response.json()
44
}
45