Action

Add to Readwise

Posted by sylumer, Last update over 3 years ago - Unlisted

Adds either the selected text, or if no selected text, the content of the draft to Readwise.

Get your access token via https://readwise.io/access_token

Steps

  • script

    function postToReadwise(p_strText)
    {
    	const BASEURL = "https://readwise.io/api/v2/highlights/";
    	
    	let credReadwise = Credential.create("Readwise", "Highlight surfacing service.");
    	credReadwise.addPasswordField("token", "API Token");
    	credReadwise.authorize();
    
    	let httpMain = HTTP.create();
    	let respMain = httpMain.request(
    	{
    		"url" : BASEURL,
    		"method" : "POST",
    		"data": 
    		{
    			"highlights" : [{"text" : p_strText}]
    		},
    		"headers" :
    		{
    			"Authorization" : `Token ${credReadwise.getValue("token")}`
    		}
    	});
    
    	if (respMain.success) return true;
    	else
    	{
    		console.log(`[${respMain.statusCode}] ${respMain.error}`);
    		return false;
    	}
    }
    
    if (editor.getSelectedText().length > 0) postToReadwise(editor.getSelectedText());
    else postToReadwise(draft.content);

Options

  • After Success Default
    Notification Info
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.