Publish to Ghost
Publish Blog to Ghost Site Endpoint
Section titled “Publish Blog to Ghost Site Endpoint”Use the following endpoint to publish a blog post via the API.
Endpoint
Section titled “Endpoint”POST /api/v1/public/integrations/ghost/publishAuthentication
Section titled “Authentication”Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYCode Examples
Section titled “Code Examples”// Example: Publish a new blog post to Ghostconst postData = { credentials: { websiteUrl: "https://your-ghost-blog.com", // Your Ghost site's Admin URL apiKey: "YOUR_GHOST_ADMIN_API_KEY" // Ghost Admin API Key }, content: { title: "My Awesome Ghost Post via API", htmlContent: "<h1>Hello Ghost World</h1><p>This post was published using the API.</p>", status: "published", // Options: 'published', 'draft', 'scheduled' // Optional: Add tags // tags: ["api", "javascript"] }};
// Endpoint: {API_ENDPOINTS.INTEGRATIONS.GHOST.PUBLISH}fetch('https://api.blogz.ai/api/v1/public/integrations/ghost/publish', { method: 'POST', // Use POST to create a new post headers: { 'Authorization': 'Bearer YOUR_API_KEY', // Your Blogz API Key 'Content-Type': 'application/json' }, body: JSON.stringify(postData) // Send Ghost credentials and content}).then(response => { // Expecting JSON like { success: true, postUrl: "...", postId: "..." } return response.json();}).then(data => console.log('Post published successfully to Ghost:', data)).catch(error => console.error('Error publishing to Ghost:', error));// Define interfaces based on PublicApiController.ts for Ghostinterface IntegrationGhostCredentials { websiteUrl: string; // Ghost Admin URL apiKey: string; // Ghost Admin API Key}
interface PublishToGhostPayloadContent { title: string; htmlContent: string; status?: "published" | "draft" | "scheduled"; tags?: string[]; // Optional: Ghost tags}
interface PublishToGhostRequestBody { credentials: IntegrationGhostCredentials; content: PublishToGhostPayloadContent;}
// Assuming a similar response structureinterface PublishToGhostResponse { success: boolean; message?: string; postUrl?: string; // URL of the created post in Ghost postId?: string; // ID of the created post in Ghost}
// Example: Publish a draft post to Ghost with tagsconst postData: PublishToGhostRequestBody = { credentials: { websiteUrl: "https://your-ghost-blog.com", apiKey: "YOUR_GHOST_ADMIN_API_KEY" }, content: { title: "My Draft Ghost Post via API", htmlContent: "<h2>Work in Progress</h2><p>This is just a draft for Ghost.</p>", status: "draft", tags: ["draft", "api-test"] }};
// Endpoint: {API_ENDPOINTS.INTEGRATIONS.GHOST.PUBLISH}fetch('https://api.blogz.ai/api/v1/public/integrations/ghost/publish', { method: 'POST', // Use POST headers: { 'Authorization': 'Bearer YOUR_API_KEY', // Your Blogz API Key 'Content-Type': 'application/json' }, body: JSON.stringify(postData)}).then(response => response.json() as Promise<PublishToGhostResponse>).then((data: PublishToGhostResponse) => { if (data.success) { console.log('Post published successfully to Ghost:', data); } else { console.error('Ghost publishing failed:', data.message || 'No specific error message.'); }}).catch((error: Error) => console.error('Error publishing to Ghost:', error));import requestsimport json
# Endpoint: {API_ENDPOINTS.INTEGRATIONS.GHOST.PUBLISH}api_url = "https://api.blogz.ai/api/v1/public/integrations/ghost/publish"blogz_api_key = "YOUR_API_KEY" # Your Blogz API Keyheaders = { "Authorization": f"Bearer {blogz_api_key}", "Content-Type": "application/json"}
# Example: Publish a new post to Ghostpost_data = { "credentials": { "websiteUrl": "https://your-ghost-blog.com", # Your Ghost site's Admin URL "apiKey": "YOUR_GHOST_ADMIN_API_KEY" # Ghost Admin API Key }, "content": { "title": "Python Ghost API Post", "htmlContent": "<p>Published to Ghost from Python!</p>", "status": "published", # 'published', 'draft', 'scheduled' # "tags": ["python", "automation"] # Optional tags }}
payload = json.dumps(post_data)
try: # Use POST to create a new post response = requests.post(api_url, headers=headers, data=payload) response.raise_for_status() # Raises HTTPError for bad responses (4XX or 5XX)
# Assuming the response body contains { "success": true, "postUrl": "...", "postId": "..." } response_data = response.json() print("Post published successfully to Ghost:") print(json.dumps(response_data, indent=2))
except requests.exceptions.RequestException as e: print(f"Error publishing to Ghost: {e}") if e.response is not None: print(f"Status Code: {e.response.status_code}") try: # Try to print JSON error response from API print(f"Response body: {e.response.json()}") except json.JSONDecodeError: print(f"Response body: {e.response.text}")except json.JSONDecodeError: # Handle cases where the successful response might not be JSON print(f"Error decoding JSON response. Status: {response.status_code}, Body: {response.text}")# Example: Publish a new blog post to Ghost# Replace YOUR_GHOST_ADMIN_API_KEY with your actual Ghost Admin API Key# Replace YOUR_API_KEY with your actual Blogz API Key# Endpoint: {API_ENDPOINTS.INTEGRATIONS.GHOST.PUBLISH}curl -X POST https://api.blogz.ai/api/v1/public/integrations/ghost/publish \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "credentials": { "websiteUrl": "https://your-ghost-blog.com", "apiKey": "YOUR_GHOST_ADMIN_API_KEY" }, "content": { "title": "My cURL Ghost Post", "htmlContent": "<h1>Published to Ghost via cURL</h1><p>This uses the Ghost Admin API Key.</p>", "status": "published" } }'{ "credentials": { "websiteUrl": "https://your-ghost-blog.com", "apiKey": "YOUR_GHOST_ADMIN_API_KEY" }, "content": { "title": "Example Ghost Post Title", "htmlContent": "<p>Your blog post content in HTML format for Ghost.</p>", "status": "published", "tags": ["optional-tag-1", "optional-tag-2"] }}