Plugin: Send to Readwise

name

Send to Readwise

icon

outbox

setting

API Key

description

Send a text selection to Readwise as a highlight to review using spaced repetition.

instructions

This plugin sends a section of text from a note in Amplenote TO Readwise under a new book called "My Amplenote". This allows you to then use Readwise's spaced repetition algorithm to review your highlight.

If you are looking for a way to pull your highlights (from books/articles) FROM Readwise into Amplenote, then you will want to use this plugin.

---

To use this plugin, you must have a Readwise account. Start by adding your Readwise API key (retrieved here) to the plugin settings.

To send a text selection to Readwise, highlight the text you want to send and choose the option for "Send to Readwise" under the extract selection menu.



Note: Readwise will de-dupe highlights, So if you send two highlights with the same text, then it will do nothing.



linkCodeblock

{
async replaceText(app, text) {
// Replace with your Readwise access token
const readwiseToken = app.settings["API Key"];
 
// Highlight data
const highlightData = {
highlights: [
{
text: text,
title: "My Amplenote"
}
]
};
 
// Function to send highlight to Readwise
async function sendHighlightToReadwise(data) {
const url = 'https://readwise.io/api/v2/highlights/';
 
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Token ${readwiseToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
 
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
 
const result = await response.json();
console.log('Highlight sent successfully:', result);
// Get the current date and time
const now = new Date();
const formattedDate = now.toLocaleDateString();
const formattedTime = now.toLocaleTimeString();
app.alert("Success! Selection sent to Readwise.");
return `${text}`;
} catch (error) {
console.error('Error sending highlight:', error);
app.alert('Error sending highlight:', error);
throw error; // Re-throw the error to be caught in replaceText
}
}
 
// Call the function to send the highlight and await its result
try {
const result = await sendHighlightToReadwise(highlightData);
return result;
} catch (error) {
console.error('Error in replaceText:', error);
app.alert("Failed to sync with Readwise");
}
}
}