type Highlight = {
text: string,
title?: string,
author?: string,
imagge_url?: string,
source_url?: string,
source_type?: string,
category?: 'books' | 'articles' | 'tweets' | 'podcasts',
note?: string,
location?: number,
location_type?: 'page' | 'order' | 'time_offset',
highlighted_at?: string,
highlight_url?: string,
}
export async function main(
token: string,
highlights: Highlight[]
) {
const response = await fetch('https://readwise.io/api/v2/highlights/', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Authorization': `Token ${token}`,
},
body: JSON.stringify({highlights})
})
if (response.status !== 200) {
throw new Error(`failed to insert highlights: invalid response status: code=${response.status}, msg=${await response.text()}`)
}
return await response.json()
}Submitted by bryan958 985 days ago