Hi @sylumer, I have tried to modify your script, but am having some weird results. When I run the below script, I get a green Drafts success message, but my console.log is empty (despite the logging in my script) and nothing is showing up to Readwise. I ran your unmodified script with success, so I’m not sure what’s going on. Any debugging tips? Thanks!
// readwise
function postToReadwise(pTitle,pAuthor,pText,pURL,pNote,pType,pDate)
{
const BASEURL = "https://readwise.io/api/v2/highlights/";
let credReadwise = Credential.create("Readwise", "Highlight surfacing service.");
credReadwise.addPasswordField("token", "API Token");
credReadwise.authorize();
let httpMain = HTTP.create();
let respMain = httpMain.request(
{
"url" : BASEURL,
"method" : "POST",
"data":
{
"highlights" : [{
"text" : pText,
"title": pTitle,
"author":pAuthor,
"source_url":pURL,
"note":pNote,
"source_type":pType,
"highlighted_at": pDate
}]
},
"headers" :
{
"Authorization" : `Token ${credReadwise.getValue("token")}`
}
});
if (respMain.success) {
console.log("yep");
return true;
}
else
{
console.log(`[${respMain.statusCode}] ${respMain.error}`);
return false;
}
}
let t = draft.processTemplate("[[display_title]]");
let h = draft.processTemplate("[[line|3..]]");
var p = Prompt.create();
p.title="Parse draft for readwise";
p.addTextField("pTitle","Title",t);
p.addTextField("pAuthor","Author","");
p.addTextView("pText","Highlight",h,{"height":150});
p.addTextField("pURL","URL","");
p.addTextField("pNote","Note","");
p.addSelect("pType","Type",["book","article","podcast"],[""],false);
p.addButton("OK");
if(p.show()){
console.log(p.fieldValues["pTitle"],p.fieldValues["pAuthor"],p.fieldValues["pText"],p.fieldValues["pURL"],p.fieldValues["pNote"],p.fieldValues["pType"],draft.createdAt.toISOString());
postToReadwise(p.fieldValues["pTitle"],p.fieldValues["pAuthor"],p.fieldValues["pText"],p.fieldValues["pURL"],p.fieldValues["pNote"],p.fieldValues["pType"],draft.createdAt.toISOString());
}
else
{
context.cancel();
}
~~~~