Action

Micro.blog Note

Posted by David Blue, Last update about 1 month ago

UPDATES

about 1 month ago

  • Directory description revised.
  • Listed publicly on the Directory.

Create a shared Micro.blog Note with the contents of the current Draft.

This action creates a single shared Note (example) with the contents of the current Draft via the Micro.blog Notes API.

Requirements

  • A Micro.blog App token. (Generated here.)
  • The numeric ID of the notebook to which you’d like to share content. (Found by opening your chosen Notebook and inspecting its web address - ex: https://micro.blog/account/notes?notebook_id=1089)

You’ll be asked for both of these upon first run of the action.

Please refer to this Action’s Issue on my Drafts-specific GitHub Repository for feedback/updates.

Steps

  • script

    /*
      Create a shared Micro.blog note with the current Draft's contents via API.
    */
    
    // At first run, you will be prompted for a Micro.blog App token (create yours at https://micro.blog/account/apps) as well as the numeric ID of the Notebook you'd like to share notes to (which you can find by opening your chosen Notebook and inspecting its web address - ex: `https://micro.blog/account/notes?notebook_id=1089`).
    
    var credential = Credential.create("Micro.blogNotes", "Provide a Micro.blog App token (see https://micro.blog/account/apps) and the numeric ID of the notebook you'd like to share to.");
    
    credential.addTextField("apptoken", "App Token");
    credential.addTextField("notebookID", "Notebook ID");
    credential.authorize();
    
    var appToken = credential.getValue("apptoken");
    var notebook = credential.getValue("notebookID");
     
    var endpoint = "https://micro.blog/notes"
    var content = draft.content
    
    // create and post HTTP request
    var http = HTTP.create();
    var response = http.request({
      "url": endpoint,
      "method": "POST",
      "encoding": "form",
      "data": {
        "notebook_id": notebook,
        "is_encrypted": "false",
        "is_sharing": "true",
        "text": content
      },
      "headers": {
        "Authorization": "Bearer " + appToken,
        "Content-Type": "multipart/form-data"
      }
    });
    
    // log response and copy the public note URL to the system clipboard
    if (response.statusCode == 200) {
    	let d = JSON.parse(response.responseText);
    	console.log("Note created and shared. URL: " + d._microblog.shared_url);
    	app.setClipboard(d._microblog.shared_url);
    	draft.setTemplateTag("notelink", d._microblog.shared_url);
    }
    
    else {
    	console.log("Micro.blog Error: " + response.error);
    	context.fail();
    }
  • insertText

    template
    [Micro Note]([[notelink]])

Options

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