Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post to Dev.to Action #49

Open
extratone opened this issue May 3, 2022 · 0 comments
Open

Post to Dev.to Action #49

extratone opened this issue May 3, 2022 · 0 comments

Comments

@extratone
Copy link
Owner

Post to Dev.to Action

Description

Post draft contents on Dev.to.


// setup and request credentials
let credential = Credential.create("Devto", "Enter your Dev.to username and API key.");

credential.addTextField("username", "Username");
credential.addPasswordField("api_key", "Dev.to API Key");
credential.authorize();

const key = credential.getValue("api_key");
const username = credential.getValue("username");

// make post
let endpoint = `https://dev.to/api/articles`;

// configure post details
// for more information, see:
// https://developers.forem.com/api
let data = {"article":
	{
	"title": draft.displayTitle,
	"body_markdown": draft.content,
	"tags": draft.tags,
	"published": "false",
	}
};

// create and post HTTP request
var http = HTTP.create();

var response = http.request({
	"url": endpoint,
	"method": "POST",
	"data": data,
	"headers": {
		"Content-Type": "application/json",
		"api-key": key,
	}
});

Object.keys(response.responseText);

var tadCon = new TadConsole("/Library/Scripts/tadcon.json");

tadCon.TA_addEntry(response.responseText);

tadCon.TA_saveLog();


// log result post URL and copy to clipboard
console.log(response.responseText);
app.setClipboard(response.responseText);
draft.setTemplateTag("devdata", response.responseText);

/*
else {
	console.log("Dev.to Error: " + response.error);
	context.fail();
}
*/
@extratone extratone changed the title # Post to Dev.to Action Post to Dev.to Action May 3, 2022
extratone added a commit that referenced this issue May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant