//native
/**
* Fetch page
* Fetch a single web page (HTML or PDF) as clean markdown, optionally extracting typed JSON with a schema.
*/
export async function main(
auth: RT.Linkup,
page_url: string,
mode: "standard" | "pro" | undefined,
render_js: boolean | undefined,
extract_images: boolean | undefined,
include_raw_content: boolean | undefined,
schema: { [key: string]: any } | undefined,
instructions: string | undefined
) {
const url = new URL("https://api.linkup.so/v1/fetch")
const hasSchema = schema != null && Object.keys(schema).length > 0
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
url: page_url,
mode: mode || undefined,
renderJs: render_js || undefined,
extractImages: extract_images || undefined,
includeRawContent: include_raw_content || undefined,
schema: hasSchema ? schema : undefined,
instructions: hasSchema ? instructions || undefined : undefined,
}),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 3 hours ago