Developer Portal
Access tools, documentation, and resources to integrate with the AskMid Motor Insurance Database API.
// Quick example: Check vehicle insurance
const response = await fetch(
'https://api.askmid.net/v1/vehicles/check',
{
method: 'POST',
headers: {
'Authorization': `Bearer $${YOUR_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
registration: 'AB12CDE'
})
}
);
Code Examples
Get started quickly with our code examples for various programming languages. These examples demonstrate how to use the AskMid API for common tasks like checking vehicle insurance status, batch processing, and handling webhooks.
Before using these examples, make sure you have an API key. You can get one by signing up for an API account.
Basic Usage
View on GitHubCheck Vehicle Insurance
// Initialize the AskMid client
const AskMid = require('askmid-api-sdk');
const client = new AskMid.Client('YOUR_API_KEY');
// Check if a vehicle is insured
async function checkVehicle(registration) {
try {
const result = await client.vehicles.check({
registration: registration
});
console.log('Insurance status:', result.insured ? 'Insured' : 'Not insured');
console.log('Policy status:', result.policyStatus);
return result;
} catch (error) {
console.error('API Error:', error.message);
}
}
// Call the function
checkVehicle('AB12CDE');
Batch Processing
View on GitHubBatch Check Multiple Vehicles
// Initialize the AskMid client
const AskMid = require('askmid-api-sdk');
const client = new AskMid.Client('YOUR_API_KEY');
// Check multiple vehicles at once
async function batchCheckVehicles(registrations) {
try {
const results = await client.vehicles.batchCheck({
registrations: registrations
});
results.forEach(result => {
console.log(`${result.registration}: ${result.insured ? 'Insured' : 'Not insured'}`);
});
return results;
} catch (error) {
console.error('API Error:', error.message);
}
}
// Call the function with multiple registrations
batchCheckVehicles(['AB12CDE', 'XY34ZAB', 'CD56EFG']);
Webhook Handling
View on GitHubHandle Insurance Status Webhooks
// Express server to handle AskMid webhooks
const express = require('express');
const bodyParser = require('body-parser');
const AskMid = require('askmid-api-sdk');
const app = express();
app.use(bodyParser.json());
const webhookSecret = 'YOUR_WEBHOOK_SECRET';
// Webhook endpoint for insurance status updates
app.post('/webhooks/askmid', (req, res) => {
const signature = req.headers['x-askmid-signature'];
// Verify webhook signature
try {
const event = AskMid.Webhooks.constructEvent(
req.body,
signature,
webhookSecret
);
// Handle different event types
switch (event.type) {
case 'vehicle.insurance.updated':
const vehicle = event.data.vehicle;
console.log(`Insurance updated for ${vehicle.registration}`);
console.log(`New status: ${vehicle.insured ? 'Insured' : 'Not insured'}`);
break;
case 'vehicle.insurance.expired':
console.log(`Insurance expired for ${event.data.vehicle.registration}`);
break;
default:
console.log(`Unhandled event type: ${event.type}`);
}
res.status(200).send('Webhook received');
} catch (err) {
console.error(`Webhook Error: ${err.message}`);
res.status(400).send(`Webhook Error: ${err.message}`);
}
});
app.listen(3000, () => {
console.log('Webhook server running on port 3000');
});
Need More Examples?
Check out our GitHub repository for more examples, including integrations with popular frameworks and libraries.
Browse GitHub Repository