//native
/**
* Get File Public URL
* Get a temporary signed URL to download a file from the HubSpot file manager. Requires the files scope (or files.ui_hidden.read).
*/
export async function main(
auth: RT.Hubspot,
file_id: string,
size: "" | "thumb" | "icon" | "medium" | "preview" | undefined,
expiration_seconds: number | undefined,
upscale: boolean | undefined
) {
const url = new URL(
`https://api.hubapi.com/files/v3/files/${file_id}/signed-url`
)
if (size != null && size !== "") url.searchParams.append("size", size)
if (expiration_seconds != null)
url.searchParams.append("expirationSeconds", String(expiration_seconds))
if (upscale) url.searchParams.append("upscale", String(upscale))
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 2 days ago