Action

List Posts from Ghost

Posted by agiletortoise, Last update 10 months ago

Demo action for working with the Ghost Admin API. This retrieves a list of your recent posts, and creates a new draft with a Markdown list of the post titles and URLs.

For more information on Ghost integration, see our integration guide

Steps

  • script

    // get posts from Ghost API
    let g = Ghost.create()
    let response = g.request({
    	"path": "/admin/posts/",
    	"method": "GET"
    })
    
    let s = ""
    if (response.success) {
    	// build a list of posts and links
    	const posts = response.responseData["posts"]
        for (let post of posts) {
    		let title = post["title"]
    		let url = post["url"]
    		s = s + `* [${title}](${url})
    `
    	}
    	// create a new draft with the list
    	let d = new Draft()
    	d.content = `# Ghost Posts
    
    ${s}
    `
    	d.update()
    	editor.load(d)
    }
    else {
    	context.fail()
    }
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.