Action

Post to Writeas

Posted by David Blue, Last update over 2 years ago

UPDATES

over 2 years ago

-Correct credential identifier

show all updates...

over 2 years ago

-Correct credential identifier

over 2 years ago

-Modified/unified the credential identifier to “Write.as.”

over 2 years ago

-Unified credential identifiers (hopefully.)

over 2 years ago

-Issue url fixed

over 2 years ago

-Description update
-Publicly listed in the Directory

Post to Write.as via the Write.as API.

The URL of the result is logged, copied to the system clipboard, and inserted in the current draft as a markdown-formatted hyperlink.

Writeas Post Example

For more information, see this action’s corresponding GitHub issue.

Steps

  • script

    // setup and request credentials
    let credential = Credential.create("Writeas", "Enter your target Writeas blog slug (collection) and Writeas/Snapas API auth token.");
    
    credential.addTextField("collection", "Collection");
    credential.addPasswordField("token", "Access Token");
    credential.authorize();
    
    const token = credential.getValue("token");
    
    // make post
    let endpoint = `https://write.as/api/posts`;
    
    // configure post details
    // for more information, see:
    // https://developers.write.as/docs/api
    let data = {
    	"body": draft.content,
    };
    
    // create and post HTTP request
    var http = HTTP.create();
    
    var response = http.request({
    	"url": endpoint,
    	"method": "POST",
    	"data": data,
    	"headers": {
    		"Authorization" : token,
    	}
    });
    
    // log result post URL and copy to clipboard
    if (response.statusCode == 201) {
    	let d = JSON.parse(response.responseText);
    	console.log("Posted to Writeas. URL: " + d.data.url);
    	app.setClipboard(d.data.url);
    	draft.setTemplateTag("walink", d.data.url);
    }
    
    else {
    	console.log("Write.as Error: " + response.error);
    	context.fail();
    }
  • insertText

    template
    - [[[display_title]]]([[walink]])

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.