FileMaker Data API with Node.js
BeginnerBuild a reusable Node.js client for the FileMaker Data API with session management, automatic token refresh, and typed responses.
What you'll learn
- How to structure a reusable FileMaker API client class
- How to manage session tokens with automatic refresh
- How to type Data API responses with TypeScript generics
- How to handle network errors vs. FM application errors
A raw fetch loop works for one-off scripts, but production Node.js integrations need session pooling, automatic re-authentication on 401 errors, and typed interfaces. A small FileMaker client class encapsulates these concerns so application code stays clean.
1/4
1
Client class skeleton
Encapsulate the base URL, credentials, and session token in a class. Provide a login method and a private request method that handles auth headers.
FileMaker Script
class FileMakerClient {
private token: string | null = null;
constructor(
private readonly host: string,
private readonly database: string,
private readonly user: string,
private readonly password: string
) {}
async login(): Promise<void> {
const resp = await fetch(
`${this.host}/fmi/data/v1/databases/${this.database}/sessions`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + btoa(`${this.user}:${this.password}`),
},
body: '{}',
}
);
const json = await resp.json();
this.token = json.response.token;
}
async logout(): Promise<void> {
if (!this.token) return;
await fetch(
`${this.host}/fmi/data/v1/databases/${this.database}/sessions/${this.token}`,
{ method: 'DELETE' }
);
this.token = null;
}
}Sign in to track your progress and pick up where you left off.
Sign in to FM Dojo