API Examples & Use Cases

See how developers use our Pincode API to build amazing features

📍

Auto-fill City/State from Pincode

Automatically populate city, state, and district fields when a user enters a pincode. Reduces form completion time and eliminates data entry errors.

Interactive Demo

Integration Code

// JavaScript Example async function autoFillFromPincode(pincode) { try { const response = await fetch( `https://apicenter.in/api/pincode/${pincode}/`, { headers: { 'X-API-Key': 'YOUR_API_KEY' } } ); if (!response.ok) { throw new Error('Pincode not found'); } const data = await response.json(); const location = data[0]; // Auto-fill form fields document.getElementById('state').value = location.state; document.getElementById('city').value = location.city; document.getElementById('district').value = location.district; } catch (error) { console.error('Error:', error); alert('Invalid pincode'); } } // Trigger on pincode input document.getElementById('pincode').addEventListener('blur', function() { if (this.value.length === 6) { autoFillFromPincode(this.value); } });

Validate Addresses in Forms

Verify that pincodes match the entered city and state, ensuring data accuracy and preventing shipping errors.

Interactive Demo

Integration Code

// JavaScript Example async function validateAddress(pincode, state, city) { try { const response = await fetch( `https://apicenter.in/api/pincode/${pincode}/`, { headers: { 'X-API-Key': 'YOUR_API_KEY' } } ); if (!response.ok) { return { valid: false, error: 'Invalid pincode' }; } const data = await response.json(); const location = data[0]; // Validate state and city match const stateMatch = location.state.toUpperCase() === state.toUpperCase(); const cityMatch = location.city.toUpperCase() === city.toUpperCase(); return { valid: stateMatch && cityMatch, actualState: location.state, actualCity: location.city, message: stateMatch && cityMatch ? 'Address is valid!' : `Mismatch! Pincode belongs to ${location.state}, ${location.city}` }; } catch (error) { return { valid: false, error: 'Validation failed' }; } } // Validate on form submit document.getElementById('address-form').addEventListener('submit', async (e) => { e.preventDefault(); const result = await validateAddress( document.getElementById('pincode').value, document.getElementById('state').value, document.getElementById('city').value ); if (result.valid) { // Proceed with form submission alert('Address validated successfully!'); } else { alert(result.message || result.error); } });
📊

Get Location-based Stats Quickly

Retrieve comprehensive location data including state, city, district, region, and postal office information for analytics and reporting.

Interactive Demo

Integration Code

// JavaScript Example async function getLocationStats(pincode) { try { const response = await fetch( `https://apicenter.in/api/pincode/${pincode}/`, { headers: { 'X-API-Key': 'YOUR_API_KEY' } } ); if (!response.ok) { throw new Error('Pincode not found'); } const data = await response.json(); const location = data[0]; return { pincode: location.pincode, state: location.state, city: location.city, district: location.district, region: location.region, offices: location.offices.length, officeDetails: location.offices }; } catch (error) { console.error('Error:', error); return null; } } // Usage const stats = await getLocationStats('400067'); console.log(`State: ${stats.state}`); console.log(`City: ${stats.city}`); console.log(`Post Offices: ${stats.offices}`);
💡

Common Use Cases

E-commerce Platforms

Auto-fill shipping addresses, validate delivery areas, and calculate shipping costs based on location.

Food Delivery Apps

Verify service areas, show delivery availability, and optimize delivery routes by district.

Real Estate Portals

Enrich property listings with location data, filter by city/district, and show area statistics.

Financial Services

Validate customer addresses for KYC, determine service eligibility by region, and generate location reports.

Logistics & Shipping

Validate pincodes, determine delivery zones, and optimize last-mile delivery routes.

Analytics & Reporting

Generate location-based insights, analyze customer distribution by state/city, and create regional dashboards.

📱

Mobile App Integration

Integrate our API into your iOS or Android app with minimal effort. Works seamlessly with React Native, Flutter, and native mobile apps.

React Native Example

// React Native Example import React, { useState } from 'react'; import { View, TextInput, Button, Text } from 'react-native'; const AddressForm = () => { const [pincode, setPincode] = useState(''); const [state, setState] = useState(''); const [city, setCity] = useState(''); const fetchLocationData = async () => { try { const response = await fetch( `https://apicenter.in/api/pincode/${pincode}/`, { headers: { 'X-API-Key': 'YOUR_API_KEY' } } ); const data = await response.json(); const location = data[0]; setState(location.state); setCity(location.city); } catch (error) { console.error('Error:', error); } }; return ( <View> <TextInput placeholder="Enter Pincode" value={pincode} onChangeText={setPincode} onBlur={fetchLocationData} /> <TextInput placeholder="State" value={state} editable={false} /> <TextInput placeholder="City" value={city} editable={false} /> </View> ); };

Flutter Example

// Flutter Example import 'package:http/http.dart' as http; import 'dart:convert'; Future<Map<String, dynamic>> getLocationData(String pincode) async { final response = await http.get( Uri.parse('https://apicenter.in/api/pincode/$pincode/'), headers: { 'X-API-Key': 'YOUR_API_KEY', }, ); if (response.statusCode == 200) { final List<dynamic> data = json.decode(response.body); return data[0]; } else { throw Exception('Failed to load location data'); } } // Usage in Widget TextField( onChanged: (value) { if (value.length == 6) { getLocationData(value).then((location) { setState(() { state = location['state']; city = location['city']; }); }); } }, )