Action

Send to Buttondown

Posted by itst, Last update 7 months ago

Basic action to send a Draft to Buttondown.

See https://buttondown.email/

Assumptions:
* Draft uses Markdown.
* First line will be used as mail subject in Buttondown.
* Second line is empty.
* Mail content in Buttondown is the Draft sans first two lines.

You need to retrieve an API key from Buttondown via https://buttondown.email/requests/api-key and copy it into the script.

Have fun!

Steps

  • script

    // Basic action to send a Draft to Buttondown
    // See https://buttondown.email/
    // Assumptions:
    //		Draft is in Markdown.
    //		First line will be used as mail subject in Buttondown.
    //		Second line is empty.
    //		Mail content in Buttondown is the Draft minus the first two lines.
    // Have fun!
    
    const BASE_URL = "https://api.buttondown.email";
    const ENDPOINT = "/v1/emails";
    const METHOD = "POST";
    
    const headers = {
      Authorization: `Token <insert token from https://buttondown.email/requests/api-key>`,
    };
    
    let draftdata = {
        subject: draft.content.split("\n", 1)[0],
    	body: draft.content.substring(draft.content.indexOf("\n") + 2),
        status: "draft",
    };
    
    let http = HTTP.create(); // create HTTP object  
          
        let response = http.request({  
          "url": BASE_URL + ENDPOINT,
          "method": METHOD,
          "headers": headers,
          "data": draftdata,
        });  
          
        if (response.success) {  
          console.log(response.responseText);  
          console.log(response.responseData);  
        }  
        else {  
          console.log(response.statusCode);  
          console.log(response.error);  
        }

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.