Lesterius is a European FileMaker Business Alliance Platinum member that operates in Belgium, France, the Netherlands, Portugal and Spain. We are creative business consultants who co-create FileMaker Platform based solutions with our customers.
Sharing knowledge takes part of our DNA, that's why we developed this library to make the FileMaker Data API easy-to-use with PHP.
Break the limits of your application!
Richard Carlton Consulting is a full-stack Claris FileMaker development consultancy, serving clients globally with any and all FileMaker-related needs. We also publish the largest and most complete video training course for the FileMaker Community.
This library is a PHP wrapper for the Claris FileMaker Data API. It supports version 17/18/19 Data API commands, though if you use an 18 command (metadata commands for ex) on 17, it will fail.
You will be able to use every functions like it's documented in your FileMaker server Data Api documentation (accessible via https://[your server domain]/fmi/data/apidoc).
General FileMaker document on the FMS 17 Data API is available here
General FileMaker document on the FMS 18 Data API is available here
General FileMaker document on the FMS 19 Data API is available here
This fork is to bring greater out of the box compatibility to the myFMApiLibrary, vs the Lesterius upstream code. We're immensely grateful for the hard work Lesterius put in.
- PHP >= 5.5
- PHP cURL extension
- PHP mbstring extension
- PHP >= 7.1
- PHP cURL extension
- PHP mbstring extension
The recommended way to install it is through Composer.
composer require rcconsulting/myfmapilibrary-for-php:\>=2.0.0
After installing, you need to notate that you'll use this library, and require Composer's autoloader:
use \RCConsulting\FileMakerApi\DataApi;
require_once __DIR__ . '/vendor/autoload.php';
- Enable the FileMaker Data API on your FileMaker Server Admin Console.
- Create a user in your FileMaker database, with a custom privilege set that has at least the 'fmrest' extended privilege
- Define records & layouts access for this user
Login with credentials:
// Please note that the library does not currently support external data source authentication
$dataApi = new \RCConsulting\FileMakerApi\DataApi('https://test.fmconnection.com/fmi/data', 'MyDatabase');
$dataApi->login('filemaker api user', 'filemaker api password');
One-line example of Login with Credentials:
// Arguments: DAPI URL, Database Name, DAPI User, DAPI Password, SSL Verification Enabled?, Force Legacy HTTP 1.1?
$dataApi = new \RCConsulting\FileMakerApi\DataApi('https://test.fmconnection.com/fmi/data','MyDatabase', "DAP_User", "DAPI_Pass_1234~", True, False);
Login with oauth:
// Please note that RCC has not tested OAuth logins. We welcome any PR's which improve support.
$dataApi = new \RCConsulting\FileMakerApi\DataApi('https://test.fmconnection.com/fmi/data', 'MyDatabase');
$dataApi->loginOauth('oAuthRequestId', 'oAuthIdentifier');
// It is highly recommended to log out at each script or large process end. The Data API tokens last 15 minutes after last use, and so will hold a slot open for 15 minutes after your last connection if you do not clean up after yourself. Additionally, logout() does not destroy the DataAPI object you created (via new) previously, but it does clean out any authorization tokens from the object.
$dataApi->logout();
// Call login method first
$data = [
'FirstName' => 'John',
'LastName' => 'Doe',
'email' => 'johndoe@acme.inc',
'RepeatingField(1)' => 'Test'
];
$scripts = [
[
'name' => 'ValidateUser',
'param' => 'johndoe@acme.inc',
'type' => RCConsulting\FileMakerApi\DataApi::SCRIPT_PREREQUEST
],
[
'name' => 'SendEmail',
'param' => 'johndoe@acme.inc',
'type' => RCConsulting\FileMakerApi\DataApi::SCRIPT_POSTREQUEST
]
];
$portalData = [
'lunchDate' => '17/04/2013',
'lunchPlace' => 'Acme Inc.'
];
try {
$recordId = $dataApi->createRecord('layout name', $data, $scripts, $portalData);
} catch(\Exception $e) {
// handle exception
}
// Call login method first
try {
$dataApi->deleteRecord('layout name', $recordId, $script);
} catch(\Exception $e) {
// handle exception
}
// Call login method first
try {
$recordId = $dataApi->editRecord('layout name', $recordId, $data, $lastModificationId, $portalData, $scripts);
} catch(\Exception $e) {
// handle exception
}
// Call login method first
$portals = [
[
'name' => 'Portal1',
'limit' => 10
],
[
'name' => 'Portal2',
'offset' => 3
]
];
try {
$record = $dataApi->getRecord('layout name', $recordId, $portals, $scripts);
} catch(\Exception $e) {
// handle exception
}
// Call login method first
$sort = [
[
'fieldName' => 'FirstName',
'sortOrder' => 'ascend'
],
[
'fieldName' => 'City',
'sortOrder' => 'descend'
]
];
try {
$record = $dataApi->getRecords('layout name', $sort, $offset, $limit, $portals, $scripts);
} catch(\Exception $e) {
// handle exception
}
// Call login method first
$query = [
[
'fields' => [
['fieldname' => 'FirstName', 'fieldvalue' => '==Test'],
['fieldname' => 'LastName', 'fieldvalue' => '==Test'],
],
'options' => [
'omit' => false
]
]
];
try {
$results = $dataApi->findRecords('layout name', $query, $sort, $offset, $limit, $portals, $scripts, $responseLayout);
} catch(\Exception $e) {
// handle exception
}
try {
$dataApi->executeScript($layout, $scriptName, $scriptParameters);
} catch(\Exception $e) {
// handle exception
}
// Call login method first
$data = [
'FieldName1' => 'value',
'FieldName2' => 'value'
];
try {
$dataApi->setGlobalFields('layout name', $data);
} catch(\Exception $e) {
// handle exception
}
// Call login method first
$containerFieldName = 'Picture';
$containerFieldRepetition = 1;
// replace 'upload' below with the name="value" of the file input element of your web form
$filepath = $_FILES['upload']['tmp_name'];
$filename = $_FILES['upload']['name'];
try {
$dataApi->uploadToContainer('layout name', $recordId, $containerFieldName, $containerFieldRepetition, $filepath, $filename);
} catch(\Exception $e) {
// handle exception
}
// Call login method first
$containerFieldName = 'Picture';
$containerFieldRepetition = 1;
$filepath = '/usr/home/acme/pictures/photo.jpg';
try {
$dataApi->uploadToContainer('layout name', $recordId, $containerFieldName, $containerFieldRepetition, $filepath);
} catch(\Exception $e) {
// handle exception
}
// useful when not explicitly logging into data api, but already have valid token
// note that this implicitly sets the token retrieval date to now()
$dataApi->setApiToken($token);
// also supported
$dataApi->setApiToken($token, $tokenDate); // + unix timestamp
// returns current api token (without checking if it's valid)
$token = $dataApi->getApiToken();
// to check if the token is expired:
if ($dataApi->isApiTokenExpired()) {
// token expired
} else {
// do stuff
}
// to refresh the token in the case you've ever previously logged into the data api with this instance of the class
// currently only works with a data api username/password combo (ie not oauth)
if ($dataApi->refreshToken()) {
// success
}
// Validate whether the session authorization token we're using ... is actually valid ... according to FileMaker Server
if ($dataApi->validateTokenWithServer()){
// token is valid according to FMS!
} else {
// token has expired according to FMS!
}