Publish to WordPress
Publish Blog to WordPress Site Endpoint
Section titled “Publish Blog to WordPress Site Endpoint”Use the following endpoint to publish a blog post via the API. If you have multiple WordPress sites integrated, provide the credentials for the specific site you want to publish to.
The API supports all WordPress REST API parameters including post scheduling, custom slugs, featured media, categories, tags, custom meta fields, and more. All optional parameters are documented in the examples below.
Endpoint
Section titled “Endpoint”POST /api/v1/public/integrations/wordpress/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 WordPress with advanced optionsconst postData = { credentials: { websiteUrl: "https://myblog.example.com", username: "wp_api_user", password: "wp_api_application_password" // WordPress Application Password }, content: { title: "My Awesome Blog Post via API", content: "<h1>Hello World</h1><p>This post was published using the API.</p>", status: "publish", // Options: 'publish', 'draft', 'pending', 'private', 'future' excerpt: "A brief description of this amazing post", slug: "awesome-blog-post-api", author: 1, // Author ID featured_media: 123, // Featured image ID comment_status: "open", // 'open' or 'closed' ping_status: "open", // 'open' or 'closed' format: "standard", // 'standard', 'aside', 'chat', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio' sticky: false, categories: [1, 2], // Array of category IDs tags: [5, 6, 7], // Array of tag IDs meta: { custom_field: "Custom value", seo_description: "SEO meta description" } }};
// Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.PUBLISH}fetch('https://api.blogz.ai/api/v1/public/integrations/wordpress/publish', { method: 'POST', // Use POST to create a new post headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify(postData) // Send credentials and content}).then(response => { // Expecting JSON like { success: true, postUrl: "...", postId: "..." } return response.json();}).then(data => console.log('Post published successfully:', data)).catch(error => console.error('Error publishing to WordPress:', error));// Define interfaces (can be imported or defined inline)interface IntegrationWordpressCredentials { websiteUrl: string; username: string; password: string; // WordPress Application Password}
type IntegrationWordPressPostStatus = "publish" | "draft" | "pending" | "private" | "future";type IntegrationWordPressPostFormat = "standard" | "aside" | "chat" | "gallery" | "link" | "image" | "quote" | "status" | "video" | "audio";type IntegrationWordPressCommentStatus = "open" | "closed";type IntegrationWordPressPingStatus = "open" | "closed";
interface PublishToWordPressPayloadContent { // Required fields title: string; content: string; status: IntegrationWordPressPostStatus;
// Optional fields from WordPress REST API date?: string; // ISO8601 datetime format date_gmt?: string; // ISO8601 datetime format slug?: string; password?: string; author?: number; // Author ID excerpt?: string; featured_media?: number; // Featured media ID comment_status?: IntegrationWordPressCommentStatus; ping_status?: IntegrationWordPressPingStatus; format?: IntegrationWordPressPostFormat; meta?: Record<string, any>; // Meta fields object sticky?: boolean; template?: string; categories?: number[]; // Array of category IDs tags?: number[]; // Array of tag IDs}
interface PublishToWordPressRequestBody { credentials: IntegrationWordpressCredentials; content: PublishToWordPressPayloadContent;}
interface PublishToWordPressResponse { isPublished: boolean; link: string; id: string; status: string; type: IntegrationWordPressPostStatus;}
// Example: Publish a comprehensive post with multiple parametersconst postData: PublishToWordPressRequestBody = { credentials: { websiteUrl: "https://myblog.example.com", username: "wp_api_user", password: "wp_api_application_password" }, content: { title: "My Comprehensive Post via API", content: "<h2>Advanced Post Features</h2><p>This post demonstrates all available parameters.</p>", status: "publish", excerpt: "A comprehensive example of WordPress API integration", slug: "comprehensive-api-post", author: 1, featured_media: 123, comment_status: "open", ping_status: "open", format: "standard", sticky: false, categories: [1, 2], // Category IDs tags: [5, 6, 7], // Tag IDs meta: { custom_field: "Custom value", seo_description: "SEO meta description" } }};
// Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.PUBLISH}fetch('https://api.blogz.ai/api/v1/public/integrations/wordpress/publish', { method: 'POST', // Use POST headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify(postData)}).then(response => response.json() as Promise<PublishToWordPressResponse>).then((data: PublishToWordPressResponse) => { if (data.isPublished) { console.log('Post published successfully:', data); } else { console.error('Publishing failed:', data.status || 'No specific error message.'); }}).catch((error: Error) => console.error('Error publishing to WordPress:', error));import requestsimport jsonfrom datetime import datetime
# Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.PUBLISH}api_url = "https://api.blogz.ai/api/v1/public/integrations/wordpress/publish"api_key = "YOUR_API_KEY"headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
# Example: Publish a comprehensive post with advanced optionspost_data = { "credentials": { "websiteUrl": "https://myblog.example.com", "username": "wp_api_user", "password": "wp_api_application_password" # Use WordPress Application Password }, "content": { "title": "Python API Post with Advanced Features", "content": "<h2>Published from Python!</h2><p>This post demonstrates advanced WordPress API features.</p>", "status": "publish", # Options: 'publish', 'draft', 'pending', 'private', 'future' "excerpt": "A comprehensive Python API integration example", "slug": "python-api-advanced-post", "author": 1, # Author ID "featured_media": 123, # Featured image ID "comment_status": "open", # 'open' or 'closed' "ping_status": "open", # 'open' or 'closed' "format": "standard", # 'standard', 'aside', 'chat', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio' "sticky": False, "categories": [1, 2], # Array of category IDs "tags": [5, 6, 7], # Array of tag IDs "meta": { "custom_field": "Custom value from Python", "seo_description": "SEO meta description", "python_version": "3.9" } }}
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:") print(json.dumps(response_data, indent=2))
except requests.exceptions.RequestException as e: print(f"Error publishing to WordPress: {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 (though it should be) print(f"Error decoding JSON response. Status: {response.status_code}, Body: {response.text}")# Example: Publish a comprehensive blog post to WordPress with advanced options# Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.PUBLISH}curl -X POST https://api.blogz.ai/api/v1/public/integrations/wordpress/publish \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "credentials": { "websiteUrl": "https://myblog.example.com", "username": "wp_api_user", "password": "wp_api_application_password" }, "content": { "title": "My Advanced cURL Post", "content": "<h1>Published via cURL</h1><p>This post demonstrates advanced WordPress API features.</p>", "status": "publish", "excerpt": "A comprehensive cURL API integration example", "slug": "advanced-curl-post", "author": 1, "featured_media": 123, "comment_status": "open", "ping_status": "open", "format": "standard", "sticky": false, "categories": [1, 2], "tags": [5, 6, 7], "meta": { "custom_field": "Custom value from cURL", "seo_description": "SEO meta description" } } }'# Ensure you use a WordPress Application Password for the 'password' field.{ "credentials": { "websiteUrl": "https://myblog.example.com", "username": "wp_api_user", "password": "wp_api_application_password" }, "content": { "title": "Example Post Title", "content": "<p>Your blog post content in HTML format goes here.</p>", "status": "publish", "excerpt": "A brief description of your post", "slug": "example-post-title", "author": 1, "featured_media": 123, "comment_status": "open", "ping_status": "open", "format": "standard", "sticky": false, "categories": [1, 2], "tags": [5, 6, 7], "meta": { "custom_field": "Custom value", "seo_description": "SEO meta description" } }}