Readme

Reader docs here: https://readwise.io/reader_api

Adapted from the example code. Fetches items from Readwise Reader given a token, and optional updatedAfter and location parameters.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
type ReaderLocation = "new" | "archive" | "feed" | "later";
interface ReaderItem {
id: string;
url: string;
title: string;
author: string;
source: string;
category: string;
location: ReaderLocation;
tags: {};
site_name: string;
word_count: number;
created_at: string;
updated_at: string;
published_date: number;
summary: string;
image_url: string;
content: null;
source_url: string;
notes: string;
parent_id: null;
reading_progress: number;
}
export async function readwiseReaderDocumentList(
token: string,
updatedAfter: string | undefined,
location: ReaderLocation | undefined,
): Promise<ReaderItem[]> {
let fullData = [];
let nextPageCursor = null;
while (true) {
const queryParams = new URLSearchParams();
if (nextPageCursor) {
queryParams.append("pageCursor", nextPageCursor);
}
if (updatedAfter) {
queryParams.append("updatedAfter", updatedAfter);
}
if (location) {
queryParams.append("location", location);
}
console.log("Making export api request with params " + queryParams.toString());
const response = await fetch("https://readwise.io/api/v3/list/?" + queryParams.toString(), {
method: "GET",
headers: {
Authorization: `Token ${token}`,
},
});
const responseJson = await response.json();
fullData.push(...responseJson["results"]);
nextPageCursor = responseJson["nextPageCursor"];
if (!nextPageCursor) {
break;
}
}
return fullData;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 19, 2024