Outbound API Configuration
Configure Odoo to send data to external systems automatically based on triggers and events.
Step-by-Step Configuration
Step 1: Create Base Configuration
- Navigate to Settings > Technical > BJ API > API Configurations
API Configurations menu in Technical Settings
- Click Create
New API Configuration form
- Set Request Type to "Out" for outbound synchronization
Select "Out" for outbound data synchronization
Step 2: Configure External API
Request URL
Configure the external API endpoint URL
Enter the complete external API endpoint:
https://api.example.com/partners
HTTP Method
Select a single HTTP method (required for outbound):
- GET: Query external data
- POST: Send new data
- PUT: Update existing data
- DELETE: Remove data
Outbound configurations require exactly one HTTP method to be selected.
Step 3: Set Timeout Parameters
Configure timeouts to prevent hanging requests:
Timeout configuration
- Connection Timeout: Maximum time to establish connection (default: 5 seconds)
- Read Timeout: Maximum time to wait for response (default: 15 seconds)
Example configuration:
Connection Timeout: 10 # seconds
Read Timeout: 30 # seconds
Step 4: Configure Authentication
Basic Authentication
Basic Authentication configuration
Authorization Type: Basic Auth
Login: api_user
Password: secure_password
Generated header:
Authorization: Basic dXNlcjpwYXNz
Bearer Token
Bearer Token configuration
Authorization Type: Bearer Token
Bearer Token: sk_live_abc123xyz789
Generated header:
Authorization: Bearer sk_live_abc123xyz789
Step 5: Define Source Model and Filters
Model and filter configuration
Model Selection
Choose the Odoo model to synchronize:
res.partner
- Contactsproduct.product
- Productssale.order
- Sales Ordersaccount.move
- Invoices
Filter Domain
Apply conditions to select specific records:
# Only sync active customers
[('active', '=', True), ('customer_rank', '>', 0)]
# Sync orders from last 7 days
[('create_date', '>=', (datetime.now() - timedelta(days=7)).strftime('%Y-%m-%d'))]
Step 6: Create Field Mappings
Configure field mappings
Map Odoo fields to external API structure:
Odoo Field | External API Key | Value Type | Notes |
---|---|---|---|
name | full_name | Plain | Customer name |
email_address | Plain | Email field | |
phone | contact_number | Plain | Phone number |
id | external_id | Plain | Unique identifier |
partner_id.name | company_name | Relational | Company reference |
Step 7: Add Custom Headers
Configure custom HTTP headers
Configure additional HTTP headers:
# Headers Tab
Content-Type: application/json
X-API-Version: 2.0
X-Client-Id: odoo-integration
Step 8: Configure Automation Triggers
Manual Execution
Call the method directly in server actions:
record = self.env['res.partner'].browse(partner_id)
config = self.env.ref('module.api_config_xml_id')
config._make_outbound_http_request(record, config.id, timeout=60)
Cron Jobs
Schedule automated synchronization
Schedule regular synchronization:
- Create a Scheduled Action
- Set the model to
bj.api.sync.config
- Configure the Python code:
# Sync all modified partners every hour
partners = env['res.partner'].search([
('write_date', '>=', datetime.now() - timedelta(hours=1))
])
config = env.ref('module.outbound_partner_config')
for partner in partners:
config._make_outbound_http_request(partner, config.id)
Base Automation
Trigger on record events:
- Create an Automated Action
- Set the model (e.g.,
res.partner
) - Choose trigger: On Creation, On Update, On Deletion
- Add server action to call the API
Outbound Request Flow
Trigger Event → Record Selection → Field Mapping → HTTP Request Construction
→ External API Call → Response Processing → Logging
Example Configurations
Example 1: Send New Customers to CRM
Name: Customer to CRM Sync
Request Type: Out
Model: res.partner
HTTP Method: POST
Request URL: https://crm.example.com/api/customers
Filter Domain: [('customer_rank', '>', 0)]
Example 2: Update Product Inventory
Name: Inventory Update
Request Type: Out
Model: product.product
HTTP Method: PUT
Request URL: https://inventory.system.com/api/products
Filter Domain: [('type', '=', 'product')]
Example 3: Delete Cancelled Orders
Name: Remove Cancelled Orders
Request Type: Out
Model: sale.order
HTTP Method: DELETE
Request URL: https://orders.api.com/remove
Filter Domain: [('state', '=', 'cancel')]
Batch Processing
For large datasets, configure batch processing:
# Pagination Settings
Is Paginated: ✓
Page Size: 100
This sends records in batches of 100 to optimize performance.
Error Handling
The module provides automatic error handling:
- Automatic Retry: Failed requests are retried with exponential backoff
- Detailed Logging: All errors logged in
bj.api.log
- Graceful Degradation: Partial failures don't block the system
- Status Code Handling: Different handling based on HTTP status
Performance Optimization
- Use appropriate batch sizes (50-200 records)
- Apply efficient domain filters to reduce dataset size
- Monitor API rate limits to avoid throttling
- Cache frequently accessed data when possible
- Use connection pooling for high-volume synchronization
Testing Your Configuration
- Create a test record in your Odoo model
- Manually trigger the synchronization
- Check the logs in BJ API > Logs
- Verify the external system received the data
- Test error scenarios (wrong URL, invalid auth)