Update WordPress Settings
Update WordPress Settings Endpoint
Section titled “Update WordPress Settings Endpoint”Use this endpoint to update WordPress integration settings. You can:
- Send a single site object in
settingsto update fields, or - Send an array of site objects in
settingsto replace the entire list of WordPress sites.
Endpoint
Section titled “Endpoint”PATCH /api/v1/public/integrations/wordpress/update-settingsAuthentication
Section titled “Authentication”Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYCode Examples
Section titled “Code Examples”// Example A: Update a single WordPress site's settingsconst settingsToUpdate = { isIntegrated: true, autoPublish: false, credentials: { websiteUrl: "https://myblog.example.com", username: "wp_api_user", password: "wp_api_application_password", // The Application Password is not your main WordPress admin password. // It acts as an API key specifically for publishing content. // We store it securely using industry-standard encryption to protect your account. },};
fetch( // Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.UPDATE_SETTINGS} "https://api.blogz.ai/api/v1/public/integrations/wordpress/update-settings", { method: "PATCH", // Use PATCH for partial updates headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ settings: settingsToUpdate }), // Send only the settings to update }) .then((res) => res.json()) .then((data) => console.log("WordPress settings updated:", data)) .catch((error) => console.error("Error updating WordPress settings:", error));
// Example B: Replace ALL WordPress sites with an array (multi-site)const allSites = [ { id: "site-1", label: "My Main Site", isIntegrated: true, autoPublish: true, isWebsiteValid: true, credentials: { websiteUrl: "https://site-one.example.com", username: "wp_user_1", password: "wp_app_password_1", }, }, { id: "site-2", label: "Blog #2", isIntegrated: false, autoPublish: false, isWebsiteValid: false, credentials: { websiteUrl: "https://site-two.example.com", username: "wp_user_2", password: "wp_app_password_2", }, },];
fetch( // Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.UPDATE_SETTINGS} "https://api.blogz.ai/api/v1/public/integrations/wordpress/update-settings", { method: "PATCH", headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ settings: allSites }), // Replaces entire list }) .then((res) => res.json()) .then((data) => console.log("All WordPress sites replaced:", data)) .catch((error) => console.error("Error replacing WordPress sites:", error));interface IntegrationWordpressCredentials { websiteUrl?: string; username?: string; password?: string; // The Application Password is not your main WordPress admin password. // It acts as an API key specifically for publishing content. // We store it securely using industry-standard encryption to protect your account.}
interface IntegrationWordPress { id: string; label?: string; isIntegrated?: boolean; isWebsiteValid?: boolean; autoPublish?: boolean; credentials?: IntegrationWordpressCredentials;}
// Define the expected response structureinterface UpdateIntegrationResponse { success: boolean; integration?: IntegrationWordPress | IntegrationWordPress[]; // Updated integration state}
// Example A: Enable/disable fields for a single site (legacy style)const settingsToUpdate: Partial<IntegrationWordPress> = { isIntegrated: true, autoPublish: false, credentials: { websiteUrl: "https://myblog.example.com", username: "wp_api_user", password: "wp_api_application_password", },};
fetch( // Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.UPDATE_SETTINGS} "https://api.blogz.ai/api/v1/public/integrations/wordpress/update-settings", { method: "PATCH", // Use PATCH for partial updates headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ settings: settingsToUpdate }), // Send only the settings to update }) .then((response) => response.json() as Promise<UpdateIntegrationResponse>) .then((data: UpdateIntegrationResponse) => console.log("WordPress settings updated:", data) ) .catch((error: Error) => console.error("Error updating WordPress settings:", error) );
// Example B: Replace ALL WordPress sites with an arrayconst allSites: IntegrationWordPress[] = [ { id: "site-1", label: "My Main Site", isIntegrated: true, autoPublish: true, isWebsiteValid: true, credentials: { websiteUrl: "https://site-one.example.com", username: "wp_user_1", password: "wp_app_password_1", }, },];
fetch( // Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.UPDATE_SETTINGS} "https://api.blogz.ai/api/v1/public/integrations/wordpress/update-settings", { method: "PATCH", headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ settings: allSites }), }) .then((res) => res.json() as Promise<UpdateIntegrationResponse>) .then((data) => console.log("All WordPress sites replaced:", data)) .catch((error: Error) => console.error("Error updating WordPress settings:", error) );import requestsimport json
# Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.UPDATE_SETTINGS}api_url = "https://api.blogz.ai/api/v1/public/integrations/wordpress/update-settings"api_key = "YOUR_API_KEY"headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
# Example A: Update username and disable integration (single site)# Only include fields you want to change.settings_to_update = { "settings": { "isIntegrated": True, "autoPublish": False, "credentials": { "websiteUrl": "https://myblog.example.com", "username": "wp_api_user", "password": "wp_api_application_password" # The Application Password is not your main WordPress admin password. # It acts as an API key specifically for publishing content. # We store it securely using industry-standard encryption to protect your account. } }}
payload = json.dumps(settings_to_update)
try: # Use PATCH for partial updates response = requests.patch(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, "integration": { ... } } response_data = response.json() print("WordPress settings updated successfully:") print(json.dumps(response_data, indent=2))
except requests.exceptions.RequestException as e: print(f"Error updating WordPress settings: {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: print(f"Error decoding JSON response: {response.text}")
# Example B: Replace ALL WordPress sites with an arrayall_sites = { "settings": [ { "id": "site-1", "label": "My Main Site", "isIntegrated": True, "autoPublish": True, "isWebsiteValid": True, "credentials": { "websiteUrl": "https://site-one.example.com", "username": "wp_user_1", "password": "wp_app_password_1" } } ]}
response = requests.patch(api_url, headers=headers, data=json.dumps(all_sites))print(response.json())# Example A: Update a single site. Only include the fields you intend to modify.# Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.UPDATE_SETTINGS}curl -X PATCH https://api.blogz.ai/api/v1/public/integrations/wordpress/update-settings \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "settings": { "isIntegrated": true, "autoPublish": false, "credentials": { "websiteUrl": "https://myblog.example.com", "username": "wp_api_user", "password": "wp_api_application_password" } } }'# The Application Password is not your main WordPress admin password.# It acts as an API key specifically for publishing content.# We store it securely using industry-standard encryption to protect your account.
# Example B: Replace ALL WordPress sites with an array# Endpoint: {API_ENDPOINTS.INTEGRATIONS.WORDPRESS.UPDATE_SETTINGS}curl -X PATCH https://api.blogz.ai/api/v1/public/integrations/wordpress/update-settings \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "settings": [ { "id": "site-1", "label": "My Main Site", "isIntegrated": true, "autoPublish": true, "isWebsiteValid": true, "credentials": { "websiteUrl": "https://site-one.example.com", "username": "wp_user_1", "password": "wp_app_password_1" } } ] }'{ "settings": { "isIntegrated": true, "autoPublish": false, "credentials": { "websiteUrl": "https://myblog.example.com", "username": "wp_api_user", "password": "wp_api_application_password" } }}