@letsparky/api-v2-client
v1.0.7
Published
TypeScript client for the LetsParky API V2
Maintainers
Readme
Letsparky API V2 Client
TypeScript toolkit for working with the Letsparky API v2. It wraps every published endpoint with typed helpers, sensible validation, and Node/Browser support.
Installation
npm i @letsparky/api-v2-clientQuick Start
import LetsParkyClient, { Environment } from '@letsparky/api-v2-client';
const client = new LetsParkyClient({
apiKey: process.env.LETSPARKY_API_KEY!,
environment: Environment.PRODUCTION,
});
const profile = await client.getProfile();
console.log(`Hello ${profile.first_name}!`);Authentication
- API key: pass
apiKeyas shown above. - Email/password: provide
email&passwordand the client will authenticate automatically (client.authenticate()is also available).
Usage Examples
Devices
// List paginated devices
const devicePage = await client.devices.listPaginated({ page: 1, limit: 20 });
// Search public catalogue by coordinates (GET /devices/search/location)
const search = await client.devices.searchByLocation({ lat: 40.74, lng: -73.99, radius: 750 });
console.log(`Found ${search.data.total} devices in range`);
// Attach device to a parking area
await client.devices.assignToParkingArea(devicePage.data[0].id, {
parking_area_id: '9b1a6c89-5ddf-4e80-91f0-e3b46c379999',
association_type: 'ENTRY',
});
// Unblock a device
await client.devices.unblock(device_id)Parking Areas
// List areas visible to the current user
const areasResponse = await client.parkingAreas.list({ page: 1, limit: 10 });
const names = areasResponse.data.data.map((area) => area.name);
// Create a new area (POST /parking-areas)
const created = await client.parkingAreas.create({
name: 'Downtown Garage - Level 3',
type: 'AREA',
total_spots: 120,
is_public: false,
});
console.log(created.data.id);Device Logs & Monitoring
const deviceSnapshot = await client.devices.listPaginated({ page: 1, limit: 1 });
const [firstDevice] = deviceSnapshot.data;
if (!firstDevice) throw new Error('No devices available');
const logs = await client.deviceLogs.list({ device_id: firstDevice.id, limit: 50 });
console.log(`Fetched ${logs.data.pagination.total} log entries`);
const analytics = await client.deviceLogs.getAnalytics(firstDevice.id, {
start_time: new Date(Date.now() - 7 * 86400000).toISOString(),
end_time: new Date().toISOString(),
});Payments & Memberships
const payments = await client.payments.list({ status: 'CAPTURED', limit: 10 });
const publicMemberships = await client.memberships.getPublic({ page: 1, limit: 5 });License
ISC
