Updated 09082022-151236
var credential = Credential.create("Pastery", "Set Pastery API key.");
credential.addTextField("ptoken", "API Key");
credential.authorize();
var psToken = credential.getValue("ptoken");
var endpoint = "https://www.pastery.net/api/paste";
var content = draft.content;
// create and post HTTP request
var http = HTTP.create();
var response = http.request({
"url": endpoint,
"method": "POST",
"encoding": "form",
"data": {
"api_key": psToken,
"language": "markdown",
"title": draft.title,
"data": content
}
});
console.log("Response: " + response.statusCode);
if (response.statusCode != 200 && response.statusCode != 202) {
context.fail();
}
else
{
var pasteryURL = response.responseText;
app.setClipboard(pasteryURL);
console.log("New paste: " + pasteryURL);
var ts = new Date();
draft.content += "\r\n\r\nPublic pastery link: " + pasteryURL + " created " + ts.toLocaleString();
// ts.toISOString();
draft.addTag("pastery");
draft.update();
}