Integration Architecture and Data Flow
Core Integration Components
The AfterShip-Odoo integration employs a webhook-driven architecture that maintains data consistency across both systems. Odoo 18 serves as the source of truth for order data and customer information. AfterShip functions as the tracking data aggregation engine, monitoring carrier updates across hundreds of shipping providers. The integration connects these systems through Odoo’s web framework and AfterShip’s Tracking API.
Your Odoo instance initiates the data flow by pushing shipment events to AfterShip. The system creates tracking numbers in AfterShip immediately after order confirmation in Odoo. This proactive approach ensures tracking visibility begins at the earliest possible moment. AfterShip then assumes responsibility for monitoring carrier data and detecting delivery exceptions or delays.
Data Synchronization Patterns
The integration uses bidirectional synchronization for optimal data consistency. Odoo sends order and tracking data to AfterShip using the Tracking API endpoints. AfterShip pushes tracking updates back to Odoo via configured webhooks. This pattern maintains real-time visibility without constant polling that would strain both systems.
Odoo’s job queue system processes incoming webhook notifications from AfterShip. This design prevents blocking operations during high-volume tracking update periods. The queue workers update Odoo sales orders, delivery orders, and customer communication records. This architecture ensures system responsiveness during peak shipping notification periods.
Webhook Configuration Strategy
AfterShip webhooks target specific endpoints within your Odoo instance. The /aftership/webhook/tracking endpoint receives all tracking update notifications. Odoo authenticates these requests using a shared secret key embedded in the webhook URL. This security measure prevents unauthorized tracking data injection.
The webhook payload contains the complete tracking object with all available fields. Odoo parses this JSON payload and maps relevant data to Odoo delivery records. The system updates tracking history, estimated delivery dates, and exception flags. This real-time update process eliminates manual tracking status checks.
Error Handling Architecture
The integration implements a retry mechanism for failed API calls. Odoo’s automated actions handle temporary AfterShip API unavailability. Failed webhook deliveries trigger exponential backoff retries from AfterShip’s infrastructure. This resilient design prevents data loss during transient network issues.
Step-by-Step Configuration
AfterShip Account Preparation
Begin by creating a dedicated AfterShip account for your Odoo integration. Navigate to AfterShip’s API settings and generate a new API key with full tracking permissions. This key authenticates all outbound requests from Odoo to AfterShip’s APIs. Store this key securely for the Odoo configuration phase.
Configure your AfterShip webhooks to point to your Odoo instance. Access the Webhook settings in your AfterShip dashboard and create a new endpoint. Use the format https://your-odoo-domain.com/aftership/webhook/tracking. Set the webhook secret to a cryptographically secure random string. This secret validates incoming webhook requests.
Odoo Module Installation
Install the AfterShip connector module from Odoo’s app store or your custom repository. The module extends Odoo’s delivery infrastructure with AfterShip integration capabilities. Enable the module in Odoo’s Apps menu and restart your Odoo instance. The system creates the necessary data models and web controllers.
Navigate to Settings > Technical > System Parameters and create a new parameter. Set the key as aftership.api_key and the value as your AfterShip API key. This secure storage method prevents API credentials from appearing in code or database dumps. The system encrypts this parameter in Odoo’s database.
Delivery Method Configuration
Open the Delivery Methods configuration in Odoo’s Inventory app. Edit each shipping method that will use AfterShip tracking. Enable the “AfterShip Tracking” option and map the carrier to the corresponding AfterShip carrier code. This mapping ensures Odoo sends tracking data to the correct carrier in AfterShip.
Configure the carrier-specific settings for each delivery method. Set the AfterShip carrier code using the standardized slug format. For example, FedEx uses “fedex”, UPS uses “ups”, and DHL Express uses “dhl”. This precise mapping guarantees proper tracking creation in AfterShip’s system.
Webhook Endpoint Setup
The AfterShip connector module automatically creates webhook endpoints during installation. Verify the endpoint functionality by accessing Settings > Technical > Webhooks. Confirm the /aftership/webhook/tracking endpoint exists and has proper authentication middleware. This validation ensures your Odoo instance can receive tracking updates.
Test the webhook connectivity using AfterShip’s webhook simulation tool. Send a sample tracking update payload to your Odoo endpoint. Monitor Odoo’s logs for successful processing and check for any authentication errors. This proactive testing identifies configuration issues before production use.
Automated Action Configuration
Create automated actions in Odoo to trigger tracking creation. Navigate to Settings > Technical > Automated Actions and create a new server action. Set the trigger condition to “When a delivery is confirmed”. This timing ensures tracking numbers sync to AfterShip immediately upon shipment.
Define the action code using Python and Odoo’s ORM methods. The code should extract tracking numbers, carrier codes, and customer information from the delivery record. It then makes the API call to AfterShip’s tracking creation endpoint. This automation eliminates manual tracking entry.
def create_aftership_tracking(records):
aftership_api = requests.Session()
aftership_api.headers.update({'aftership-api-key': env['ir.config_parameter'].get_param('aftership.api_key')})
for record in records:
tracking_data = {
'tracking': {
'tracking_number': record.carrier_tracking_ref,
'slug': record.carrier_id.aftership_slug,
'title': record.sale_id.name,
'customer_name': record.partner_id.name,
'order_id': record.sale_id.id
}
}
response = aftership_api.post('https://api.aftership.com/tracking/2023-10/trackings', json=tracking_data)
if response.status_code != 201:
_logger.error('AfterShip tracking creation failed: %s', response.text)
Order Synchronization Setup
Configure batch synchronization for existing orders with tracking numbers. Create a scheduled action that processes recent deliveries without AfterShip tracking records. This catch-up mechanism ensures historical data transfers to AfterShip. The job runs hourly during initial implementation.
Set up error notifications for failed synchronization attempts. Configure Odoo’s notification system to alert administrators when tracking creation fails. This monitoring ensures quick resolution of integration issues. The system logs detailed error information for troubleshooting.
Data Mapping and Transformation
Order Data Extraction
Odoo extracts specific order data fields for AfterShip synchronization. The system maps Odoo’s stock.picking records to AfterShip’s tracking object schema. Essential fields include tracking numbers, carrier references, and order identification data. This structured extraction ensures AfterShip receives complete tracking context.
The transformation process converts Odoo’s internal IDs to AfterShip’s expected format. Order names become tracking titles, and partner addresses transform to shipment destination information. This translation maintains data consistency while adapting to each system’s data model.
Tracking Data Normalization
AfterShip returns tracking data in a standardized format regardless of the original carrier. Odoo maps this normalized data back to delivery records and customer communication. The system processes tracking events, estimated delivery dates, and exception flags. This normalization simplifies Odoo’s tracking display logic.
The integration transforms AfterShip’s tracking statuses to Odoo’s delivery state mapping. “In Transit” becomes in_transit, “Out for Delivery” becomes out_for_delivery, and “Delivered” becomes done. This status synchronization provides accurate delivery progress within Odoo.
Customer Data Handling
Odoo sends minimal customer data to AfterShip for privacy compliance. The system includes only the customer name and order identification information. Email addresses and phone numbers remain within Odoo unless explicitly configured for notifications. This careful approach protects customer privacy.
The integration maps customer communication preferences from Odoo to AfterShip’s notification settings. Customers who opt out of marketing emails in Odoo automatically disable AfterShip promotional notifications. This preference synchronization maintains consistent customer communication policies.
Address Data Transformation
Odoo’s partner address records require transformation for AfterShip compatibility. The system concatenates street fields into single-line address format expected by AfterShip’s API. Country codes convert from Odoo’s internal representation to ISO standard format. This transformation ensures proper carrier integration.
The integration handles address validation discrepancies between systems. Odoo’s verified addresses take precedence over any carrier address suggestions. This priority prevents address corruption during the synchronization process.
Custom Field Mapping
Extended tracking data fields require custom mapping configuration. Odoo’s delivery carriers can define additional fields like insurance value, special handling instructions, or declared value. The integration maps these custom fields to AfterShip’s custom fields array.
The transformation logic handles data type conversions between systems. Odoo’s float fields become integers where required, and date fields format to ISO 8601 standard. These precise transformations prevent data format errors during synchronization.
Error Handling and Resilience
API Failure Scenarios
AfterShip API outages trigger Odoo’s retry mechanism for tracking creation. The system queues failed API calls and retries them using exponential backoff. This approach handles temporary network issues or AfterShip service degradation. Failed operations persist in the job queue for 24 hours.
Webhook delivery failures activate AfterShip’s retry policy for tracking updates. AfterShip attempts webhook delivery up to 5 times with increasing delays between attempts. This redundancy ensures Odoo receives critical tracking updates even during brief connectivity issues.
Data Validation Errors
Invalid tracking numbers generate specific error responses from AfterShip’s API. Odoo catches these errors and flags the corresponding delivery records for review. The system notifies logistics team members about invalid tracking data. This proactive alerting prevents prolonged tracking synchronization failures.
Carrier code mismatches produce mapping errors during tracking creation. Odoo logs these errors and falls back to AfterShip’s carrier detection when possible. The system suggests correct carrier codes based on tracking number patterns. This intelligent fallback reduces configuration errors.
Authentication Failures
Expired API keys cause authentication failures in both directions. Odoo detects 401 responses from AfterShip and alerts administrators to update the API key. The system continues processing existing tracking data while awaiting credential updates. This graceful degradation prevents complete integration failure.
Webhook authentication failures indicate potential security issues. Odoo logs these events with full request details for security analysis. The system blocks repeated authentication attempts from suspicious sources. This security measure protects your tracking data integrity.
Recovery Procedures
The integration includes comprehensive recovery tools for data reconciliation. Odoo’s AfterShip module provides a synchronization status dashboard that identifies missing tracking records. Administrators can trigger manual synchronization for specific time ranges or orders. This control enables quick recovery from extended outages.
Data conflict resolution procedures handle mismatches between Odoo and AfterShip. The system prioritizes Odoo’s order data over AfterShip’s information for customer details. Tracking status information from AfterShip takes precedence for delivery progress. This clear priority scheme resolves data conflicts automatically.
Testing and Validation
Connection Testing
Validate the API connection before full implementation. Use Odoo’s built-in connection tester in the AfterShip configuration menu. This tool verifies API key validity and basic connectivity to AfterShip’s services. Successful tests confirm proper network configuration and authentication.
Test webhook reception with AfterShip’s webhook simulator. Send sample tracking update payloads to verify Odoo’s parsing logic. Confirm that tracking updates properly modify delivery records and trigger customer notifications. This validation ensures the bidirectional data flow functions correctly.
Data Synchronization Verification
Create test orders with various carrier configurations to validate tracking creation. Monitor Odoo’s logs for successful API calls to AfterShip. Verify that tracking numbers appear in your AfterShip dashboard shortly after delivery confirmation. This testing confirms the automatic synchronization timing.
Validate tracking update flow by simulating carrier scan events in AfterShip. Use the tracking test feature to generate artificial tracking updates. Confirm these updates appear in Odoo’s delivery records and customer communication history. This end-to-end testing validates the complete integration cycle.
Error Scenario Testing
Simulate network failures during API calls to verify error handling. Temporarily block outbound connections to AfterShip’s API endpoints during order processing. Confirm Odoo queues these requests and retries them when connectivity restores. This testing validates the resilience mechanisms.
Test invalid data handling by creating orders with malformed tracking numbers. Verify the system properly catches these errors and flags records for manual review. Confirm that valid orders continue processing during invalid data scenarios. This testing ensures robust error isolation.
Performance Validation
Measure synchronization timing under various load conditions. Process batches of orders with tracking data to assess system performance. Verify that tracking creation completes within acceptable time limits even during peak order volumes. This performance testing identifies potential bottlenecks.
Monitor system resource usage during large synchronization jobs. Track memory consumption, database load, and API rate limiting compliance. Optimize batch sizes and processing frequency based on these metrics. This proactive monitoring prevents production performance issues.
Security Considerations
API Key Management
Store AfterShip API keys in Odoo’s system parameters with proper encryption. Never embed keys in source code or configuration files. Rotate API keys quarterly or following security policy requirements. This key management practice prevents credential exposure.
Implement IP whitelisting for AfterShip webhook calls when possible. Configure your firewall to accept connections only from AfterShip’s published IP ranges. This additional security layer prevents unauthorized webhook injection attempts.
Data Privacy Compliance
The integration design minimizes personal data exposure to AfterShip. Odoo sends only necessary order and tracking information required for shipment monitoring. Customer email addresses and phone numbers remain within Odoo unless explicitly configured for notifications. This privacy-first approach complies with data protection regulations.
Implement data retention policies for tracking history in both systems. Regularly purge old tracking data from AfterShip using their API or dashboard. Configure Odoo to archive completed delivery records according to your data retention schedule. These policies reduce data storage risks.
Webhook Security
Validate webhook signatures for all incoming AfterShip requests. Odoo’s webhook endpoint verifies the HMAC signature using your webhook secret. This cryptographic validation ensures tracking updates originate from AfterShip, not malicious actors.
Implement rate limiting on webhook endpoints to prevent denial-of-service attacks. Odoo’s web framework can throttle excessive requests from any single IP address. This protection maintains system availability during unusual traffic patterns.
Access Control
Restrict Odoo user permissions for AfterShip configuration. Grant access only to administrators and logistics team members who require integration management. Apply Odoo’s granular permission system to prevent unauthorized configuration changes.
Audit integration activity through Odoo’s logging system. Monitor for unusual patterns like unexpected tracking creations or configuration modifications. These audit trails support security investigations and compliance reporting.
Performance Optimization
API Call Efficiency
Batch tracking creation requests to minimize API calls to AfterShip. Odoo’s job queue can group multiple tracking creations into single API requests when possible. This batching reduces API overhead and improves synchronization speed.
Implement intelligent polling for tracking updates instead of constant checks. Use AfterShip’s webhook system as the primary update mechanism, with occasional API polls for reconciliation. This approach minimizes unnecessary API consumption.
Database Optimization
Index Odoo database fields used in AfterShip synchronization queries. Add indexes to tracking number fields, carrier references, and synchronization status flags. These indexes improve query performance during high-volume order processing.
Optimize Odoo’s automated action triggers for delivery confirmation events. Ensure these triggers execute efficiently without blocking other order processing operations. Monitor database locks during peak synchronization periods.
Caching Strategies
Cache AfterShip carrier codes and configuration in Odoo’s in-memory cache. Reduce API calls to AfterShip’s carrier list endpoint by caching results for 24 hours. This caching improves delivery method configuration performance.
Implement tracking update deduplication to prevent processing identical webhook payloads. Odoo can skip processing tracking updates that match the current known status. This optimization reduces database write operations during tracking synchronization.
Resource Monitoring
Monitor API rate limit usage through AfterShip’s dashboard and Odoo’s logs. Track your current usage against AfterShip’s plan limits to prevent service throttling. Implement client-side rate limiting in Odoo to stay within allocated quotas.
Profile integration performance during peak order volumes like holiday seasons. Identify bottlenecks in tracking creation, update processing, or customer notification. Scale Odoo’s worker processes based on these performance profiles.