This guide gets easy-fm from install to first successful read.
import FMHost from "@jd-data-limited/easy-fm"
const host = new FMHost("https://example.com")
FMHost represents your FileMaker Server or FileMaker Cloud base address.
const database = host.database({
database: "Contacts",
credentials: {
method: "filemaker",
username: process.env.FM_USERNAME!,
password: process.env.FM_PASSWORD!
},
externalSources: []
})
Most projects start with method: "filemaker".
If you need other auth modes, read authentication-and-sessions.md.
const contacts = database.layout("Contacts_API")
This matters because FileMaker Data API works through layouts, not directly through tables.
If a field is not available on the layout, you usually cannot read or write it through that layout.
const records = await contacts.records.list({
portals: {},
limit: 25
}).fetch()
Then use field values:
for (const record of records) {
console.log(record.fields.FirstName.value)
}
import {query as q} from "@jd-data-limited/easy-fm"
const records = await contacts.records.list({
portals: {},
requests: [
{
req: {
Status: q`Active`,
Email: q`*@example.com`
}
}
],
limit: 10
}).fetch()
query handles FileMaker escaping rules for you.
const record = records[0]
record.fields.LastSeenAt.value = new Date()
await record.commit()
Changes are local until commit() runs.
await database.close()
Do this when your script or job is finished.