Skip to content

Your First Proyog App

Prayog is a comprehensive logistics API platform that enables developers to integrate powerful shipping, tracking, and logistics management capabilities into their applications.

This guide will walk you through the entire process of setting up your first logistics integration, from authentication to creating your first shipment booking.

Setting up Authentication

Before you can start using Prayog APIs, you need to set up authentication to access our services.

  1. Get your API credentials from the Prayog dashboard after completing onboarding.

  2. Set up your base configuration in your application:

const API_BASE_URL = 'https://api.prayog.com';
const API_KEY = 'your-api-key-here';
const headers = {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
};

Onboarding Your Organization

The first step is to onboard your organization with Prayog. This establishes your account and enables access to our logistics network.

Complete Organization Registration

Use the Onboarding API to register your organization:

const onboardingData = {
customer: {
orgName: "Your Company Name",
source: "API",
reference: "initial-setup",
customerType: "BUSINESS",
emails: [{
type: "PRIMARY",
country: "IN",
email: "contact@yourcompany.com",
isVerified: false
}],
contactNumbers: [{
type: "PRIMARY",
country: "IN",
countryCode: "+91",
number: "9876543210",
isVerified: false
}],
addresses: [{
type: "REGISTERED",
pincode: 110001,
houseFlatNum: "123",
buildingName: "Tech Tower",
street: "Main Street",
area: "Business District"
}]
}
};
const response = await fetch(`${API_BASE_URL}/onboarding`, {
method: 'POST',
headers: headers,
body: JSON.stringify(onboardingData)
});

Checking Serviceability

Before creating shipments, verify if delivery is available in your target areas using the Serviceability API.

Check Pincode Serviceability

const checkServiceability = async (pincode) => {
const response = await fetch(`${API_BASE_URL}/serviceability/pincode/${pincode}`, {
method: 'GET',
headers: headers
});
const result = await response.json();
return result.serviceable;
};
// Example usage
const isServiceable = await checkServiceability(110001);
console.log(`Delivery available: ${isServiceable}`);

Creating Your First Shipment

Once onboarded and serviceability is confirmed, you can create your first shipment booking.

Book a Shipment

const bookingData = {
pickupAddress: {
name: "Your Warehouse",
address: "123 Warehouse Street",
pincode: 110001,
city: "New Delhi",
state: "Delhi",
country: "India"
},
deliveryAddress: {
name: "Customer Name",
address: "456 Customer Street",
pincode: 110002,
city: "New Delhi",
state: "Delhi",
country: "India"
},
packageDetails: {
weight: 1.5, // in kg
dimensions: {
length: 20, // in cm
width: 15,
height: 10
},
value: 1000 // in INR
},
serviceType: "EXPRESS"
};
const booking = await fetch(`${API_BASE_URL}/booking`, {
method: 'POST',
headers: headers,
body: JSON.stringify(bookingData)
});
const bookingResult = await booking.json();
console.log('Booking created:', bookingResult.trackingNumber);

Tracking Your Shipment

Use the Tracking API to monitor shipment progress and provide updates to your customers.

Get Tracking Information

const trackShipment = async (trackingNumber) => {
const response = await fetch(`${API_BASE_URL}/tracking/${trackingNumber}`, {
method: 'GET',
headers: headers
});
const trackingData = await response.json();
return trackingData;
};
// Example usage
const trackingInfo = await trackShipment('TRK123456789');
console.log('Current status:', trackingInfo.status);
console.log('Location:', trackingInfo.currentLocation);

Rate Calculation

Before booking, you can get rate estimates using the Rates and Charges API.

Calculate Shipping Rates

const getRates = async (origin, destination, weight, dimensions) => {
const rateQuery = {
origin: origin,
destination: destination,
weight: weight,
dimensions: dimensions
};
const response = await fetch(`${API_BASE_URL}/rates/calculate`, {
method: 'POST',
headers: headers,
body: JSON.stringify(rateQuery)
});
const rates = await response.json();
return rates;
};
// Example usage
const rates = await getRates(110001, 110002, 1.5, {length: 20, width: 15, height: 10});
console.log('Available rates:', rates);

Managing Delivery Slots

For scheduled deliveries, use the Slots API to manage delivery time windows.

Check Available Slots

const getAvailableSlots = async (pincode, date) => {
const response = await fetch(`${API_BASE_URL}/slots/available?pincode=${pincode}&date=${date}`, {
method: 'GET',
headers: headers
});
const slots = await response.json();
return slots;
};
// Example usage
const availableSlots = await getAvailableSlots(110001, '2024-01-15');
console.log('Available delivery slots:', availableSlots);

Error Handling and Best Practices

Implement Proper Error Handling

const apiCall = async (url, options) => {
try {
const response = await fetch(url, options);
if (!response.ok) {
const errorData = await response.json();
throw new Error(`API Error: ${errorData.message}`);
}
return await response.json();
} catch (error) {
console.error('API call failed:', error.message);
throw error;
}
};

Rate Limiting and Retry Logic

const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
const retryApiCall = async (apiFunction, maxRetries = 3) => {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await apiFunction();
} catch (error) {
if (attempt === maxRetries) throw error;
const delayTime = Math.pow(2, attempt) * 1000; // Exponential backoff
await delay(delayTime);
}
}
};

Next Steps

You’ve now successfully integrated with Prayog’s logistics APIs! Here are some next steps to enhance your integration:

  1. Explore Advanced Features: Check out our specialized APIs for reverse logistics, bulk operations, and analytics
  2. Set up Webhooks: Configure real-time notifications for shipment status updates
  3. Implement Address Validation: Use our Address API for accurate delivery locations
  4. Add HSN Code Management: Integrate tax code handling for compliance
  5. Monitor Performance: Use our reporting APIs to track delivery performance and customer satisfaction

For detailed API references and advanced use cases, explore the specific API documentation sections in this guide.