Official TypeScript client for the Mployr API
# Using npm
npm install @mployr/api-client
# Using yarn
yarn add @mployr/api-client
# Using pnpm
pnpm add @mployr/api-clientInitialize the client and make your first API call:
Create a new employee record with contact information.
const newPerson = await client.people.create({
first_name: 'John',
last_name: 'Doe',
email: 'john.doe@example.com',
phone: '+61 400 123 456',
date_of_birth: '1990-05-15',
});
console.log('Created person:', newPerson.data.id);Update an existing person's information.
const updated = await client.people.update(42, {
last_name: 'Smith',
email: 'john.smith@example.com',
});
console.log('Updated:', updated.data);Iterate through all pages of results.
async function getAllPeople() {
const allPeople: Person[] = [];
let page = 1;
let hasMore = true;
while (hasMore) {
const response = await client.people.list({
page,
per_page: 100,
});
allPeople.push(...response.data);
hasMore = page < response.pagination.last_page;
page++;
}
return allPeople;
}Handle API errors gracefully.
import { ApiError } from '@mployr/api-client';
try {
const person = await client.people.get(999);
} catch (error) {
if (error instanceof ApiError) {
console.error('API Error:', error.message);
console.error('Status:', error.status);
if (error.status === 404) {
console.log('Person not found');
} else if (error.status === 401) {
// Re-authenticate
await client.auth.login({ email, password });
}
}
}See all available methods and endpoints in the interactive API reference.