Action

Post to Writeas

Posted by David Blue, Last update 3 months ago

UPDATES

3 months ago

-Correct credential identifier

show all updates...

3 months ago

-Correct credential identifier

4 months ago

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

4 months ago

-Unified credential identifiers (hopefully.)

4 months ago

-Issue url fixed

4 months 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.