Shipping and Logistics
Guide to integrate shipping and logistics services in Sarah
Last updated: 2025-01-26
Sarah integrates with shipping and logistics services to calculate shipping costs, generate labels, and track packages.
Supported Providers
Correo Argentino
Complete integration with Correo Argentino for shipments within Argentina.
Features:
- Shipping cost calculation
- Label generation
- Package tracking
- Shipment import
Initial Configuration
1. Get Credentials
For Correo Argentino:
- Contact Correo Argentino to get API credentials
- Get:
- Username
- Password
- Client code (if applicable)
2. Configure in Sarah
- Log in to Sarah
- Go to Settings > Integrations > Shipping
- Select Correo Argentino
- Enter your credentials
- Configure environment (test or production)
- Save configuration
API Endpoints
Calculate Shipping Cost
POST /api/shipping/rates
Body:
json{
"partner": "correo-argentino",
"origin": {
"postal_code": "C1000",
"city": "Buenos Aires",
"province": "CABA"
},
"destination": {
"postal_code": "5000",
"city": "Córdoba",
"province": "Córdoba"
},
"package": {
"weight": 1.5,
"length": 30,
"width": 20,
"height": 15
}
}
Response:
json{
"rates": [
{
"service": "standard",
"name": "Standard Shipping",
"cost": 2500.00,
"estimated_days": 5
},
{
"service": "express",
"name": "Express Shipping",
"cost": 4500.00,
"estimated_days": 2
}
]
}
Get Agencies
httpGET /api/shipping/agencies?partner=correo-argentino&postal_code=5000
Response:
json{
"agencies": [
{
"id": "AG001",
"name": "Centro Agency",
"address": "Main St. 123",
"postal_code": "5000",
"city": "Córdoba"
}
]
}
Track Shipment
httpGET /api/shipping/tracking?partner=correo-argentino&tracking_number=AA123456789AR
Response:
json{
"tracking_number": "AA123456789AR",
"status": "in_transit",
"current_location": "Córdoba Distribution Center",
"events": [
{
"date": "2025-01-26T10:00:00Z",
"status": "picked_up",
"location": "Buenos Aires"
},
{
"date": "2025-01-27T14:30:00Z",
"status": "in_transit",
"location": "Córdoba Distribution Center"
}
],
"estimated_delivery": "2025-01-29"
}
Import Shipments
POST /api/shipping/import
Body:
json{
"partner": "correo-argentino",
"shipments": [
{
"tracking_number": "AA123456789AR",
"recipient": {
"name": "Juan Pérez",
"address": "Main St. 123",
"postal_code": "5000",
"city": "Córdoba"
},
"package": {
"weight": 1.5
}
}
]
}
Integration in Sales Flow
1. Calculate Shipping in Checkout
When a customer enters their postal code in checkout:
javascriptconst response = await fetch('/api/shipping/rates', {
method: 'POST',
body: JSON.stringify({
partner: 'correo-argentino',
origin: {
postal_code: storePostalCode,
city: storeCity,
province: storeProvince
},
destination: {
postal_code: customerPostalCode,
city: customerCity,
province: customerProvince
},
package: {
weight: cartWeight,
dimensions: cartDimensions
}
})
});
const { rates } = await response.json();
// Show shipping options to customer
2. Generate Label
After confirming sale:
javascript// Label is generated automatically
// Or manually from order
const response = await fetch('/api/shipping/label', {
method: 'POST',
body: JSON.stringify({
partner: 'correo-argentino',
sale_id: 789,
service: 'standard'
})
});
3. Track Shipment
Customer can track their order:
javascriptconst response = await fetch(
`/api/shipping/tracking?partner=correo-argentino&tracking_number=${trackingNumber}`
);
const tracking = await response.json();
// Show shipment status
Service Types
Correo Argentino
| Service | Description | Estimated Time |
|---|---|---|
standard | Standard shipping | 5-7 business days |
express | Express shipping | 2-3 business days |
priority | Priority shipping | 1-2 business days |
Shipment States
| State | Description |
|---|---|
pending | Shipment created, waiting for pickup |
picked_up | Package picked up |
in_transit | In transit |
out_for_delivery | On the way to destination |
delivered | Delivered |
exception | Problem with shipment |
returned | Returned to sender |
Data Structure
Credentials
typescriptinterface ShippingIntegrationCredentials {
username: string;
password: string;
client_code?: string; // Optional
}
Package
typescriptinterface Package {
weight: number; // kg
length?: number; // cm
width?: number; // cm
height?: number; // cm
value?: number; // Declared value
}
Address
typescriptinterface Address {
postal_code: string;
city: string;
province: string;
street?: string;
number?: string;
floor?: string;
apartment?: string;
}
Factory Pattern
Sarah uses a factory pattern to support multiple providers:
typescriptimport { getShippingService } from '@/lib/shipping/factory';
const service = getShippingService(
'correo-argentino',
credentials,
'production'
);
const rates = await service.calculateRates(origin, destination, package);
Add New Provider
To add a new provider:
- Create a class that extends
BaseShippingService - Implement required methods
- Add provider to factory
- Update documentation
Best Practices
- Validate addresses: Verify postal codes are valid
- Calculate dimensions: Include dimensions for more accurate calculations
- Handle errors: Implement error handling for API failures
- Cache rates: Cache rates for common addresses
- Track shipments: Update shipment status periodically
- Notify customers: Send notifications when status changes
Troubleshooting
Error calculating rates
- Verify credentials: Ensure they're correct
- Verify addresses: Postal codes must be valid
- Review logs: Look for errors in provider API
- Verify environment: Ensure you use correct environment
Shipment doesn't track
- Verify tracking number: Must be valid
- Review provider: Ensure you use correct provider
- Verify in provider: Check directly on provider website
Label doesn't generate
- Verify data: All required fields must be present
- Review logs: Look for errors in generation
- Verify permissions: Ensure you have permissions to generate labels
Additional Resources
- Correo Argentino Documentation
- Correo Argentino API (if available)
- Shipping Guide - Shipping features in Sarah
Support
If you need help:
- Review integration logs
- Verify provider configuration
- Contact Sarah support with error details