0

Create Post

by
Published Aug 26, 2024

Create a new post

Script ghostcms Verified

The script

Submitted by hugo697 Bun
Verified 652 days ago
1
import GhostAdminAPI from '@tryghost/admin-api'
2

3
type Ghostcms = {
4
	apiKey: string
5
	apiUrl: string
6
}
7

8
export async function main(
9
	resource: Ghostcms,
10
	payload: {
11
		title: string
12
		slug?: string
13
		status: 'draft' | 'published' | 'scheduled'
14
		featured?: boolean
15
		custom_excerpt?: string
16
		tags?: {
17
			name: string
18
		}[]
19
		authors?: {
20
			id: string
21
		}[]
22
	}
23
) {
24
	const apiClient = new GhostAdminAPI({
25
		url: resource.apiUrl,
26
		version: 'v5.87',
27
		key: resource.apiKey
28
	})
29

30
	const response = await apiClient.posts.add(payload)
31

32
	return response
33
}
34