8.0 KiB
Wix Integration for ALwrity
This document describes the Wix integration feature that allows ALwrity users to publish their generated blogs directly to their Wix websites.
Overview
The Wix integration provides a seamless way for ALwrity users to:
- Connect their Wix account to ALwrity
- Publish blog posts directly from ALwrity to their Wix website
- Manage blog categories and tags
- Import images to Wix Media Manager
Architecture
Backend Components
-
WixService (
services/wix_service.py)- Handles OAuth 2.0 authentication with Wix
- Manages token refresh and validation
- Converts content to Wix Ricos JSON format
- Imports images to Wix Media Manager
- Creates and publishes blog posts
-
Wix Routes (
api/wix_routes.py)/api/wix/auth/url- Get OAuth authorization URL/api/wix/auth/callback- Handle OAuth callback/api/wix/connection/status- Check connection status/api/wix/publish- Publish blog post to Wix/api/wix/categories- Get blog categories/api/wix/tags- Get blog tags/api/wix/disconnect- Disconnect Wix account
Frontend Components
-
WixTestPage (
frontend/src/components/WixTestPage/WixTestPage.tsx)- Test page for Wix integration functionality
- Connection status display
- Blog post creation and publishing form
- Category and tag management
-
Enhanced Publisher (
frontend/src/components/BlogWriter/Publisher.tsx)- Integrated Wix publishing into existing blog writer
- Connection status checking
- Enhanced error handling and user feedback
Setup Instructions
1. Wix App Configuration
- Go to Wix Developers
- Create a new app or use an existing one
- Configure OAuth settings:
- Redirect URI:
http://localhost:3000/wix/callback(for development) - Scopes:
BLOG.CREATE-DRAFT,BLOG.PUBLISH,MEDIA.MANAGE
- Redirect URI:
- Note down your Client ID (no Client Secret required for Wix Headless OAuth)
2. Environment Configuration
Add the following environment variables to your .env file:
# Wix Integration (Headless OAuth - Client ID only, no Client Secret required)
WIX_CLIENT_ID=your_wix_client_id_here
WIX_REDIRECT_URI=http://localhost:3000/wix/callback
Important Note: Wix Headless OAuth only requires a Client ID and does NOT use a Client Secret. This is different from traditional OAuth implementations and is designed for public clients like single-page applications.
3. Database Setup
The integration requires storing user tokens securely. You'll need to:
- Create a table to store Wix tokens:
CREATE TABLE wix_tokens (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id TEXT NOT NULL,
access_token TEXT NOT NULL,
refresh_token TEXT,
expires_at TIMESTAMP,
member_id TEXT, -- Store member ID for third-party app requirements
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
- Implement token storage and retrieval functions in the WixService
4. Important: Third-Party App Requirements
CRITICAL: When creating blog posts as a third-party app, Wix requires a memberId field. This is mandatory and cannot be omitted. The integration will:
- Automatically retrieve the current member ID during the OAuth flow
- Store the member ID with the user's tokens
- Use the member ID when creating blog posts
This requirement is enforced by Wix's API and cannot be bypassed.
Usage
1. Testing the Integration
- Navigate to
/wix-testin your ALwrity application - Click "Connect to Wix" to authorize the integration
- Complete the OAuth flow in the popup window
- Once connected, you can:
- Load categories and tags from your Wix blog
- Create and publish test blog posts
- Check connection status
2. Publishing from Blog Writer
- Generate your blog content using ALwrity's AI tools
- Use the CopilotKit action: "Publish to Wix"
- The system will:
- Check your Wix connection status
- Convert your content to Wix format
- Import any images to Wix Media Manager
- Create and publish the blog post
- Return the published post URL
API Endpoints
Authentication
Get Authorization URL
GET /api/wix/auth/url?state=optional_state
Handle OAuth Callback
POST /api/wix/auth/callback
Content-Type: application/json
{
"code": "authorization_code",
"state": "optional_state"
}
Connection Management
Check Connection Status
GET /api/wix/connection/status
Disconnect Account
POST /api/wix/disconnect
Publishing
Publish Blog Post
POST /api/wix/publish
Content-Type: application/json
{
"title": "Blog Post Title",
"content": "Blog content in markdown",
"cover_image_url": "https://example.com/image.jpg",
"category_ids": ["category_id_1"],
"tag_ids": ["tag_id_1", "tag_id_2"],
"publish": true
}
Content Management
Get Blog Categories
GET /api/wix/categories
Get Blog Tags
GET /api/wix/tags
Content Format Conversion
The integration automatically converts ALwrity's markdown content to Wix's Ricos JSON format:
Supported Elements
- Headings:
# Heading→HEADINGnode - Paragraphs: Regular text →
PARAGRAPHnode - Images: External URLs → Imported to Wix Media Manager
- Lists: Markdown lists →
ORDERED_LIST/BULLETED_LISTnodes
Example Conversion
Markdown Input:
# Welcome to My Blog
This is a paragraph with some content.
## Features
- Feature 1
- Feature 2
Ricos JSON Output:
{
"nodes": [
{
"type": "HEADING",
"nodes": [{
"type": "TEXT",
"textData": {
"text": "Welcome to My Blog",
"decorations": []
}
}],
"headingData": { "level": 1 }
},
{
"type": "PARAGRAPH",
"nodes": [{
"type": "TEXT",
"textData": {
"text": "This is a paragraph with some content.",
"decorations": []
}
}],
"paragraphData": {}
}
]
}
Error Handling
The integration includes comprehensive error handling for:
- Authentication Errors: Invalid tokens, expired sessions
- Permission Errors: Insufficient Wix app permissions
- Content Errors: Invalid content format, missing required fields
- Network Errors: API timeouts, connection issues
Security Considerations
- Token Storage: Access and refresh tokens are stored securely
- HTTPS: All API calls use HTTPS in production
- Scope Limitation: Only requests necessary permissions
- Token Refresh: Automatic token refresh when expired
Troubleshooting
Common Issues
-
"Wix account not connected"
- Solution: Use the Wix Test Page to connect your account
-
"Insufficient permissions"
- Solution: Reconnect your Wix account with proper permissions
-
"Failed to import image"
- Solution: Check image URL accessibility and format
-
"Content format error"
- Solution: Ensure content is valid markdown
Debug Mode
Enable debug logging by setting the log level to DEBUG in your environment:
LOG_LEVEL=DEBUG
Future Enhancements
- Scheduled Publishing: Support for scheduled blog posts
- Bulk Publishing: Publish multiple posts at once
- Content Templates: Pre-defined content templates for Wix
- Analytics Integration: Track published post performance
- Advanced Formatting: Support for more Ricos node types
Support
For issues or questions about the Wix integration:
- Check the troubleshooting section above
- Review the Wix API documentation
- Check the application logs for detailed error messages
- Contact the development team