Construct a client

Call DataApi with a FileMaker layout and an adapter. ADT typegen normally creates these clients for you, but the same public function is available when you need to create one yourself.

Use a generated client

For each layout in adt.config.json, typegen creates a client that is ready to import:

Copy
import { ContactsLayout } from "@/config/schemas/filemaker/client";

const response = await ContactsLayout.list({ limit: 25 });

The generated client includes the layout name, a WebViewerAdapter, and runtime schemas for its fields and portals. Regenerate it after changing the fields on the FileMaker layout.

See Generate types with Typegen for the complete generation workflow.

Create a client manually

DataApi is a function, not a class. Call it without new:

Copy
import { DataApi, WebViewerAdapter } from "@adt/fmdapi";
import { ZContacts, ZContactsPortals } from "../Contacts";

export const ContactsLayout = DataApi({
  adapter: new WebViewerAdapter({
    scriptName: "ADT_execute_data_api",
  }),
  layout: "API_Contacts",
  schema: {
    fieldData: ZContacts,
    portalData: ZContactsPortals,
  },
});

Create one client for each FileMaker layout your app uses. The layout remains fixed for the lifetime of that client.

DataApi options

Option Type Required Description
adapter Adapter Yes Sends the client's operations to FileMaker. Web Viewer apps use WebViewerAdapter. You can also supply an object that implements the public Adapter interface.
layout string Yes The exact FileMaker layout used for every request from this client.
schema.fieldData StandardSchemaV1<FieldData> When schema is present Validates and transforms field data returned by read operations. Zod schemas implement the Standard Schema interface.
schema.portalData Record<string, StandardSchemaV1<FieldData>> No Maps each portal name to the schema that validates its returned records.

The schema is optional. Without one, the client returns field values as Record<string, unknown> unless you supply TypeScript types explicitly:

Copy
type ContactFields = {
  Name: string;
  Status: "Active" | "Inactive";
};

const ContactsLayout = DataApi<ContactFields>({
  adapter: new WebViewerAdapter({
    scriptName: "ADT_execute_data_api",
  }),
  layout: "API_Contacts",
});

Generic types provide compile-time checking only. Passing schema also checks data returned at runtime. See Validation and transformation for the validation behavior.

Warning  Do not use zodValidators The old zodValidators option is not supported. Replace it with schema, or rerun typegen to regenerate the client.

Returned client

DataApi returns an object with the configured layout and these methods:

  • Read records: list, listAll, get, find, findOne, findFirst, maybeFindFirst, and findAll

  • Write records: create, update, and delete

  • Work with the layout: layoutMetadata and containerUpload

  • Use adapter capabilities: executeScript and any additional public members supplied by a custom adapter

See Record methods and pagination for every method's arguments, return value, and error behavior. See WebViewerAdapter for its connection, batching, pagination, and container-upload options.