Where exactly do you put in the iA Writer credentials?

I was trying to use the Action at: https://actions.getdrafts.com/a/1PS

I have the iA Writer credentials. Where does one put that in the script?

Also, does this action work on macOS?

This is the script:

const baseURL = "ia-writer://x-callback-url/write/";

var credential = Credential.create("IA-Writer", "IA-Writer Token");

credential.addTextField("token", "Token");

var result = credential.authorize();

if (!result) {

   alert("Failed to obtain credentials. Please check and retry");
   context.cancel("Failed to obtain credentials");

}
else {

   // Find all drafts in the inbox - could be changed to another folder, or to include tags
   var inboxDrafts = Draft.query('','inbox',[]);

   var myDrafts = [];

   // Put all the title lines in an array for the prompt
   for (d in inboxDrafts) {
      myDrafts.push(inboxDrafts[d].title);
   }

   var p = Prompt.create();
   p.title = "Choose Drafts"
   p.addTextField("path", "Save Path", '/', {})
   p.addSelect("theDrafts","Drafts",myDrafts,[],true);
   
   p.addButton("Ok");
   p.show();

   if (p.buttonPressed == "Ok") {

      var chosenDrafts = p.fieldValues["theDrafts"];
      if (chosenDrafts.length == 0) {
         alert("No Drafts were chosen");
      }
      else {

			basePath = p.fieldValues["path"]
			if (basePath.slice(-1) != "/") {
				basePath += "/"
			}
			for (var d=0;d < chosenDrafts.length; d++) {

            var a = myDrafts.indexOf(chosenDrafts[d]);
            // create and configure callback object
            var cb = CallbackURL.create();
            cb.baseURL = baseURL;
            
            cb.addParameter("auth-token", credential.getValue("token"));
            cb.addParameter("path", basePath+inboxDrafts[a].processTemplate("[[safe_title]]"+".txt"));
            cb.addParameter("text", inboxDrafts[a].content);

            var success = cb.open();

            if (success) {
               console.log("File created: "+ cb.callbackResponse.path);
            }
            else {
               if (cb.status == "cancel") {
                  context.cancel();
               }
               else {
                  context.fail(cb.callbackResponse.errorMessage);
               }
            }
         }
      }
   }
}

macosxguru

Credentials are handled by Drafts. They should pop-up to be completed the first time an action using the credentials is run.

Thank you.

macosxguru

You probably already know, but it does work for both iOS and Mac.

I’ve pushed a small update to the action directory description to make the use of the auth token clearer.

Cheers

Thank you for an useful action.

macosxguru

I’m glad you found it helpful