Interactive Examples
Learn by doing with step-by-step code examples in multiple languages
Beginner
5 min
Create Your First Shipment
Learn how to create a shipment with address validation and carrier selection
Intermediate
10 min
Real-time Package Tracking
Implement tracking updates with webhooks for automated notifications
Advanced
15 min
Batch Label Generation
Process hundreds of orders efficiently with batch operations
Create Your First Shipment
Learn how to create a shipment with address validation and carrier selection
Beginner
5 min
npm install @atoship/sdkimport { atoshipSDK } from '@atoship/sdk';
const atoship = new atoshipSDK({
apiKey: 'your_api_key'
});
async function createShipment() {
try {
// Create shipment
const shipment = await atoship.shipments.create({
from_address: {
name: "John Doe",
company: "atoship Inc",
street1: "123 Main St",
city: "San Francisco",
state: "CA",
zip: "94105",
country: "US",
phone: "415-123-4567"
},
to_address: {
name: "Jane Smith",
street1: "456 Oak Ave",
city: "Los Angeles",
state: "CA",
zip: "90001",
country: "US",
phone: "213-987-6543"
},
parcel: {
length: 10,
width: 8,
height: 4,
weight: 16 // ounces
}
});
console.log('Shipment created:', shipment.id);
console.log('Tracking number:', shipment.tracking_number);
// Get rates for the shipment
const rates = await atoship.shipments.getRates(shipment.id);
console.log('Available rates:', rates);
// Select the cheapest rate
const cheapestRate = rates.sort((a, b) => a.amount - b.amount)[0];
console.log('Selected rate:', cheapestRate);
// Purchase label
const label = await atoship.labels.create({
shipment_id: shipment.id,
rate_id: cheapestRate.id
});
console.log('Label URL:', label.label_url);
return label;
} catch (error) {
console.error('Error creating shipment:', error);
}
}
// Run the example
createShipment();Pro Tips:
- Always validate addresses before creating shipments
- Compare rates across multiple carriers for best prices
- Save tracking numbers for customer notifications
Next Steps
Ready to implement these examples in your application?