Action

Send to Raindrop

Posted by Joshua Oliphant, Last update 11 months ago

This action allows you to send a Draft to Raindrop, a bookmark manager. It uses the same title for the bookmark title, and gets the first (assuming only) link as the link to bookmark.

Steps

  • script

    // Create a Raindrop credential
    let raindropCredential = Credential.create("Raindrop.io", "Enter your Raindrop.io API token.");
    raindropCredential.addTextField("token", "API Token");
    
    // Authorize the credential to prompt the user for input
    raindropCredential.authorize();
    
    // Get the API token from the credential
    let token = raindropCredential.getValue("token");
    
    // Check if the token is available
    if (!token) {
        console.log("Error: Raindrop token not found. Please enter your Raindrop.io API token.");
        context.fail();
    } else {
        let link = draft.processTemplate("[[body]]"); // Use the body content of the current draft as the link
    
        // Remove leading and trailing whitespace from the link, including newline characters
        link = link.trim();
        let title = draft.processTemplate("[[title]]");
        title = title.replace(/^#\s+/, '');
    
        // Create HTTP client
        let http = HTTP.create();
    
        // Define headers and payload
        const headers = { "Authorization": `Bearer ${token}` };
        console.log(headers)
        const raindrop = {
            "link": link,
            "title": title
        };
    
        // Log the raindrop
        console.log(`Posting raindrop: ${JSON.stringify(raindrop)}`);
    
        // Make the HTTP request
        http.request({
            "url": "https://api.raindrop.io/rest/v1/raindrop",
            "method": "POST",
            "headers": headers,
            "data": raindrop,
            "timeout": 10000, // Adjust the timeout as needed
            "callback": function (error, response) {
                if (error) {
                    console.error("Error posting raindrop:", error);
                    context.fail();
                    return;
                }
                // Check if the response status is not 200
                if (response.statusCode !== 200) {
                    console.log(`Error posting raindrop: ${response.statusCode} ${response.error}`);
                    context.fail();
                    return;
                }
                console.log(`Raindrop posted: ${response.body}`);
            }
        });
    }
    

Options

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